将字符串->数组->集合的转换
下面展示一些 内联代码片
。
@Test
public void test1() {
HashMap<Integer,String > hashMap=new HashMap<>();
//1.将字符串通过。分割转化为字符数组
String []a="日益努力,而后风生水起。众生皆苦,你也不能认输。".split("。");
//System.out.println(Arrays.toString(a));
int i=0;
//2.遍历数组将数组元素放到集合里面
for ( String s:a) {
i++;
hashMap.put(i,s);
}
System.out.println(hashMap);
}
效果图:
重点知识点:
字符串的分割:split()方法