Ints join() function | Guava | Java
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 paramters:
- 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 returnst a string containing the supplied int values separated by separator.
Below examples illustrate the Ints.join() method:
Example 1:
// Java code to show implementation of // Guava's Ints.join() method import com.google.common.primitives.Ints; import java.util.Arrays; class GFG { // Driver's code public static void main(String[] args) { // Creating an integer array int[] arr = { 2, 4, 6, 8, 10 }; // Using Ints.join() method to get a // string containing the elements of array // separated by a separator System.out.println(Ints.join(", ", arr)); } } |
2, 4, 6, 8, 10
Example 2:
// Java code to show implementation of // Guava's Ints.join() method import com.google.common.primitives.Ints; import java.util.Arrays; class GFG { // Driver's code public static void main(String[] args) { // Creating an integer array int[] arr = { 3, 5, 7, 9, 11 }; // Using Ints.join() method to get a // string containing the elements of array // separated by a separator System.out.println(Ints.join("-", arr)); } } |
3-5-7-9-11
Recommended Posts:
- Ints contains() function | Guava | Java
- Ints max() function | Guava | Java
- Ints min() function | Guava | Java
- Ints concat() function | Guava | Java
- Ints toArray() function | Guava | Java
- Ints asList() function | Guava | Java
- Ints indexOf() function | Guava | Java
- Ints lastIndexOf() function | Guava | Java
- Ints Class | Guava | Java
- Java Guava | Ints.compare() method with Examples
- Java Guava | Ints.hashCode() method with Examples
- Java Guava | Ints.indexOf(int[] array, int[] target) method with Examples
- Java Guava | Chars.join() method with Examples
- Java Guava | Shorts.join() method with Examples
- Java Guava | Booleans.join() 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.



