The join() method of Longs Class in the Guava library is used to combine or join all the given long values separated by a separator. These long values are passed a parameter to this method. This method also takes the separator as the parameter. This method returns a String which is the result of join operation on the specified long values.
For example: join(“-“, 1L, 2L, 3L) returns the string “1-2-3”.
Syntax:
public static String join(String separator, long… array)
Parameters: This method accepts two mandatory parameters:
- separator: which is the character that occurs in between the joined long values.
- array: which is an array of long values that are to be joined.
Return Value: This method returns a string containing all the given long values separated by separator.
Below programs illustrate the use of this method:
Example 1:
// Java code to show implementation of // Guava's Longs.join() method import com.google.common.primitives.Longs; import java.util.Arrays; class GFG { // Driver's code public static void main(String[] args) { // Creating a long array long[] arr = { 2, 4, 6, 8, 10 }; // Using Longs.join() method to get a // string containing the elements of array // separated by a separator System.out.println(Longs.join("#", arr)); } } |
2#4#6#8#10
Example 2:
// Java code to show implementation of // Guava's Longs.join() method import com.google.common.primitives.Longs; import java.util.Arrays; class GFG { // Driver's code public static void main(String[] args) { // Creating a long array long[] arr = { 3, 5, 7, 9, 11 }; // Using Longs.join() method to get a // string containing the elements of array // separated by a separator System.out.println(Longs.join("*", arr)); } } |
3*5*7*9*11
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- Java Guava | Floats.min() method with Examples
- Java Guava | Chars.min() method with Examples
- Java Guava | Doubles.max() method with Examples
- Java Guava | Longs.min() method with Examples
- Java Guava | Chars.max() method with Examples
- Java Guava | Chars.contains() method with Examples
- Java Guava | Longs.max() method with Examples
- Java Guava | Floats.contains() method with Examples
- Java Guava | Doubles.contains() method with Examples
- Java Guava | Doubles.min() method with Examples
- Java Guava | Shorts.max() method with Examples
- Java Guava | Floats.max() method with Examples
- Java Guava | Longs.contains() method with Examples
- Java Guava | Shorts.min() method with Examples
- Java Guava | Shorts.contains() method with Examples
- Java Guava | Booleans.contains() method with Examples
- Java Guava | Bytes.contains() method with Examples
- Java Guava | Doubles.hashCode() method with Examples
- Java Guava | Longs.hashCode() method with Examples
- Java Guava | Ints.hashCode() 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.

