Shorts.join()是Guava庫中Shorts類的一種方法,它返回所有給定的short值(由分隔符分隔)的組合字符串。例如,join(“-”,(short)1,(short)2,(short)3)返回字符串“1-2-3”。
用法:
public static String join(String separator, short... array)
參數:
- separator:在結果字符串的連續值之間應出現的文本(而不是在開頭或結尾)。
- array:短值數組,可能為空。
返回值:包含提供的簡短值(由分隔符分隔)的字符串。
示例1:
// Java code to show implementation of
// Guava's Shorts.join() method
import com.google.common.primitives.Shorts;
import java.util.Arrays;
class GFG {
// Driver's code
public static void main(String[] args)
{
// Creating a short array
short[] arr = { 2, 4, 6, 8, 10 };
// Using Shorts.join() method to get a
// string containing the elements of array
// separated by a separator
System.out.println(Shorts.join("#", arr));
}
}
輸出:
2#4#6#8#10
示例2:
// Java code to show implementation of
// Guava's Shorts.join() method
import com.google.common.primitives.Shorts;
import java.util.Arrays;
class GFG {
// Driver's code
public static void main(String[] args)
{
// Creating a short array
short[] arr = { 3, 5, 7, 9, 11 };
// Using Shorts.join() method to get a
// string containing the elements of array
// separated by a separator
System.out.println(Shorts.join("*", arr));
}
}
輸出:
3*5*7*9*11
相關用法
- Java Guava Doubles.min()用法及代碼示例
- Java Guava Doubles.contains()用法及代碼示例
- Java Guava Floats.contains()用法及代碼示例
- Java Guava Bytes.contains()用法及代碼示例
- Java Guava Longs.contains()用法及代碼示例
- Java Guava Shorts.min()用法及代碼示例
- Java Guava Longs.min()用法及代碼示例
- Java Guava Chars.min()用法及代碼示例
- Java Guava Floats.min()用法及代碼示例
- Java Guava Longs.max()用法及代碼示例
- Java Guava Doubles.max()用法及代碼示例
- Java Guava Chars.max()用法及代碼示例
- Java Guava Floats.max()用法及代碼示例
- Java Guava Booleans.contains()用法及代碼示例
- Java Guava Shorts.contains()用法及代碼示例
注:本文由純淨天空篩選整理自Sahil_Bansall大神的英文原創作品 Java Guava | Shorts.join() method with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。