Guava
Google Guava 是 Google 为 Java 1.6 编写的核心库,这个库简化了你的代码,使它易写、易读、易于维护。它能提高你的 工作效率,让你从大量重复的底层代码中脱身。
1 Guava String转List,map
List carIdList = Splitter.on(char).omitEmptyStrings().trimResults().splitToList(carIds);
根据char分割字符串
omitEmptyStrings 去掉分割后空的字符串
trimResults 去掉分后后字符串中的空格
splitToList 处理结果处理成List类型
转换MAP(感觉很少用)
Map map= Splitter.on(";").omitEmptyStrings().trimResults().withKeyValueSeparator(",").split(“a,c;b,d; e,f ;hello,csdn”);
2 Guava 读取文件
File file = new File(路径);
List strings = Files.readLines(file, Charsets.UTF_8);
3 生成固定长度的的list 和map
ImmutableList of = ImmutableList.of(“a”, “b”, “c”, “d”);
ImmutableMap<String,String> map = ImmutableMap.of(“key1”, “value1”, “key2”, “value2”);
4 创建 MAP 和 List
5.把一个List转换为int数组:
int[] array2 = Ints.toArray(list);
6 把List转换为String
String join = String.join( char,integers);
根据char连接