List轉(zhuǎn)數(shù)組:
List<String> list = new ArrayList<>();
list.add("1");
list.add("2");
String[] strings = new String[list.size()];
list.toArray(strings);
數(shù)組轉(zhuǎn)list:
(1) list不可加減
String[] studentIds = new String[] {"1","2"};
List<String> list = Arrays.asList(studentIds);
(2)list可加減
String[] studentIds = new String[] {"1","2"};
List<String> list = new ArrayList<>();
Collections.addAll(list, studentIds);
list.add("3");
list.remove("2");
數(shù)組去重:
String[] studentIds = new String[] {"1","1","2"};
List<String> newStudentIds = new ArrayList<>();
for(String studentId : studentIds) {
//過濾掉重復(fù)的
if(!newStudentIds.contains(studentId)) {
newStudentIds.add(studentId);
}
}
String[] array =new String[newStudentIds.size()];
newStudentIds.toArray(array);