处理集合循环中删除问题


 
java 代码
 
  1. List<string> wordList = </string>new LinkedList<string>();  </string>
  2.       
  3.     // Assign some words  
  4.     for (int i=0; i
  5.       wordList.add("word " + (i+1) + ": " '" + args[i] + "'"); 
  6.     } 
  7.      
  8.     // Remove all words with "1" in them.  
  9.         Impossible with for/in! 
  10.     for (Iterator i = wordList.iterator(); i.hasNext(); ) { 
  11.       String word = (String)i.next(); 
  12.       if (word.indexOf("1") != -1) {  
  13.           
  14.         i.remove();  
  15.       }  
  16.     }  
  17.      

你可能感兴趣的:(java)