Saturday, July 4, 2026
HomeLanguagesJavaInts join() function | Guava | Java

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 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




// 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));
    }
}


Output: 

2, 4, 6, 8, 10

 

Example 2:
 

Java




// 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));
    }
}


Output: 

3-5-7-9-11

 

Reference: https://google.github.io/guava/releases/22.0/api/docs/com/google/common/primitives/Ints.html#join-java.lang.String-int…-
 

RELATED ARTICLES

Most Popular

Dominic
32519 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6900 POSTS0 COMMENTS
Nicole Veronica
12015 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12110 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6967 POSTS0 COMMENTS