Advertisement
Guest User

Untitled

a guest
Sep 19th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1.  
  2. public class TestLists {
  3.  
  4. public static void main(String[] args){
  5. LinkedList<String> list = new LinkedList<String>();
  6.  
  7. list.add("abc",0);
  8. list.add("def",0);
  9. list.add("xyz",1);
  10. list.add("hello",list.size());
  11. // list should be def, xyz, abc,hello
  12. System.out.println(list);
  13. list.remove(0);
  14. list.remove(list.size() - 1);
  15. list.remove(1);
  16. // list should be xyz
  17. System.out.println(list);
  18. try {
  19. for (int ii = 0; ii < 10; ii++){
  20. list.remove(0);
  21. }
  22. }
  23. catch (ListException ex) {
  24. System.out.println("EXCEPTION: " + ex);
  25. }
  26.  
  27. try {
  28. list.add("def",10);
  29. }
  30. catch (ListException ex) {
  31. System.out.println("EXCEPTION: " + ex);
  32. }
  33. try {
  34. list.get(10);
  35. }
  36. catch (ListException ex) {
  37. System.out.println("EXCEPTION: " + ex);
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement