Java Guava | Shorts.join() method with Examples
Shorts.join() is a method of Shorts class in Guava library which returns a combined string of all the given short values separated by separator. For example, join(“-“, (short) 1, (short) 2, (short) 3) returns the string “1-2-3”.
Syntax :
public static String join(String separator,
short... array)
Parameters :
- separator : The text that should appear between consecutive values in the resulting string (but not at the start or end).
- array : An array of short values, possibly empty.
Return Value: A string containing the supplied short values separated by separator.
Example-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)); } } |
chevron_right
filter_none
Output:
2#4#6#8#10
Example-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)); } } |
chevron_right
filter_none
Output:
3*5*7*9*11
Recommended Posts:
- Java Guava | Doubles.min() method with Examples
- Java Guava | Floats.min() method with Examples
- Java Guava | Bytes.contains() method with Examples
- Java Guava | Chars.max() method with Examples
- Java Guava | Longs.max() method with Examples
- Java Guava | Doubles.max() method with Examples
- Java Guava | Shorts.max() method with Examples
- Java Guava | Shorts.min() method with Examples
- Java Guava | Shorts.contains() method with Examples
- Java Guava | Floats.max() method with Examples
- Java Guava | Chars.contains() method with Examples
- Java Guava | Booleans.contains() method with Examples
- Java Guava | Floats.contains() method with Examples
- Java Guava | Chars.min() method with Examples
- Java Guava | Longs.min() method with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



