Home  >  Article  >  Java  >  The Joiner class is a class in the Guava Java library

The Joiner class is a class in the Guava Java library

PHPz
PHPzforward
2023-09-10 19:58:411340browse

Joiner类是Guava Java库中的一个类

Joiner provides various methods to handle connection operations of strings, objects, etc. let's see one Example −

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

Output

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete