Joiner provides various methods to handle connection operations of strings, objects, etc. let's see one Example −
import com.google.common.base.Joiner; import java.util.*; public class Demo{ public static void main(String[] args){ String[] my_arr = { "hel", null, "lo", "wo", "r", null, "ld" }; System.out.println("The original array is : "+ Arrays.toString(my_arr)); String my_result = Joiner.on('+').skipNulls().join(my_arr); System.out.println("The joined string is : " + my_result); } }
The original array is [hel, null, lo, wo, r, null, ld] The joined string is hel+lo+wo+r+ld
The class named Demo contains the main function, which defines an array of strings. Array converted Convert array to string and display on string. The array also contains some null values. When displaying the array, null values are removed and replaced with the " " operator, all because of the Joiner class Present in guava packets. This output is displayed on the console.
The above is the detailed content of The Joiner class is a class in the Guava Java library. For more information, please follow other related articles on the PHP Chinese website!