连接器类 Guava Java
连接器提供了处理字符串、对象等连接操作的各种方法。让我们看一个示例 -
示例
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
一个名为 Demo 的类包含定义了一个字符串数组的主函数。将该数组转换为字符串并显示在该字符串上。该数组还包含一些 null 值。在显示此数组时,这些 null 值将被删除并替换为“+”运算符,所有这些都是因为 Guava 包中存在连接器类。此输出将显示在控制台上。
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP