Guava’s Ints.join() returns a string containing the supplied int values separated by separator.
For example, join(“-“, 1, 2, 3) returns the string “1-2-3”.
Syntax:
public static String
join(String separator, int[] array)
Parameters: This method takes the following 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 int values.
Return Value: This method returns a string containing the supplied int values separated by separator.
Below examples illustrate the Ints.join() method:
Example 1:
Java
import com.google.common.primitives.Ints;
import java.util.Arrays;
class GFG {
public static void main(String[] args)
{
int [] arr = { 2 , 4 , 6 , 8 , 10 };
System.out.println(Ints.join( ", " , arr));
}
}
|
Example 2:
Java
import com.google.common.primitives.Ints;
import java.util.Arrays;
class GFG {
public static void main(String[] args)
{
int [] arr = { 3 , 5 , 7 , 9 , 11 };
System.out.println(Ints.join( "-" , arr));
}
}
|
Reference: https://google.github.io/guava/releases/22.0/api/docs/com/google/common/primitives/Ints.html#join-java.lang.String-int…-
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
26 Jul, 2021
Like Article
Save Article