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.
Java
Java
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.
// 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));
}
}
Output:
Example 2:
2#4#6#8#10
// 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));
}
}
Output:
Reference: https://guava.dev/releases/21.0/api/docs/com/google/common/primitives/Longs.html#join-java.lang.String-long...-3*5*7*9*11