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

The Joiner class is a class in the Guava Java library

PHPz
Release: 2023-09-10 19:58:41
forward
1421 people have browsed it

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);
   }
}
Copy after login

Output

The original array is [hel, null, lo, wo, r, null, ld]
The joined string is hel+lo+wo+r+ld
Copy after login

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 of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template