Remove specific string from arraylist elements containing a particular subsrtring

后端 未结 5 633
我寻月下人不归
我寻月下人不归 2021-01-24 15:00

Here is my code for arrayList ,

 String[] n = new String[]{\"google\",\"microsoft\",\"apple\"};
      final List list =  new ArrayList

        
5条回答
  •  不知归路
    2021-01-24 15:40

    use the following code.

    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Iterator;
    import java.util.List;
    
    public class RemoveElements {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
             String[] n = new String[]{"google","microsoft","apple"};
              List list =  new ArrayList();
              Collections.addAll(list, n);
              System.out.println("list"+list);
              Iterator iter = list.iterator();
              while(iter.hasNext()){
                  if(iter.next().contains("le"))
                      iter.remove();
              }
    
              System.out.println("list"+list);
        }
    
    }
    

提交回复
热议问题