JAva LIST,ArrayList常用操作
6029 ワード
Listある原素を削除
反復
stream版
反復
String strArr = "ssss,bbbbb,ssss,,bbbbb";
//
String[] arr1 = strArr.split(",");
// list
List<String> aooList = Lists.newArrayList(Arrays.asList(arr1));
Iterator<String> iterator=aooList.iterator();
while (iterator.hasNext()){
String s=iterator.next();
if(s.equals("ssss")){
iterator.remove();
}
}
stream版
String strArr = "ssss,bbbbb,ssss,,bbbbb";
//
String[] arr1 = strArr.split(",");
// list
List<String> aooList = Lists.newArrayList(Arrays.asList(arr1));
aooList.removeIf(s -> s.equals("ssss"));
List
List<String> list = aooList.stream().filter(l->!l.equals("ssss")).collect(Collectors.toList());