fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. List<String> list = new LinkedList<String>();
  13. list.add("a");
  14. list.add("b");
  15. list.add("c");
  16. System.out.println("遍历list值");
  17. System.out.println("size:"+list.size());
  18.  
  19. for( Iterator it = list.iterator(); it.hasNext(); )
  20. {
  21. System.out.println("value="+it.next());
  22. }
  23. System.out.println("删除a");
  24. list.remove("a");
  25. System.out.println("size:"+list.size());
  26.  
  27. for( Iterator it = list.iterator(); it.hasNext(); )
  28. {
  29. System.out.println("value="+it.next());
  30. }
  31. System.out.println("修改b");
  32. list.set(0, "B");// 将索引位置为1的对象e修改为对象b
  33. System.out.println("size:"+list.size());
  34.  
  35. for( Iterator it = list.iterator(); it.hasNext(); )
  36. {
  37. System.out.println("value="+it.next());
  38. }
  39. }
  40. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
遍历list值
size:3
value=a
value=b
value=c
删除a
size:2
value=b
value=c
修改b
size:2
value=B
value=c