Advertisement
Guest User

old For-loop cannot throw a ConcurrentModificationException

a guest
Nov 25th, 2015
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1.  
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.List;
  6.  
  7. public class TimTest {
  8.  
  9.   public static void main(String[] args) {
  10.     // TODO Auto-generated method stub
  11.  
  12.     List<String> list = new ArrayList<>(
  13.         Arrays.asList(new String[]{"Player1",
  14.             "Player2" , "Player3"
  15.         }));
  16.    
  17.    
  18.    
  19.    
  20.     for (int i = 0 ; i < list.size() ; i++){
  21.       System.out.println("LISTSIZE: " + list.size());
  22.       if (list.get(i).equals("Player2")){
  23.         list.add(i+1 , new String("SPLITPLAYER"));
  24.       }
  25.      
  26.       System.out.println(list.get(i) + " spielt jetzt");
  27.       try {
  28.         Thread.sleep(2000);
  29.       } catch (InterruptedException e) {
  30.         // TODO Auto-generated catch block
  31.         e.printStackTrace();
  32.       }
  33.      
  34.      
  35.     }
  36.    
  37.    
  38.   }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement