字符串 | 数组 | List对象 | |
定义 | String str = ""; |
String[] s = new String[5]; char[] s; |
List<String> list = new ArrayList<>(); |
获取长度 | str.length(); | s.length; | list.size(); |
获取子元素 | str.charAt(i); | s[i]; | list.get(i); |
List 转换为 String数组
List<String> list = new ArrayList<String>(); list.add("1"); list.add("2"); String[] ans = list.toArray(new String[list.size()]); for(String s : ans) { System.out.println(s); }
String 数组转换为 List
String[] s = new String[] {"1", "2"}; List<String> ans = Arrays.asList(s); for(String str : ans){ System.out.println(str); }