willieshi232

Untitled

Apr 13th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. 1.
  2. An ArrayList is a structure that stores a collection of objects inside itself as elements. Each element is associated with an integer index starting from 0.
  3. 2.
  4. e.
  5. 3.
  6. ArrayList<String> list = new ArrayList<String>();
  7. list.add("It");
  8. list.add("was");
  9. list.add("a");
  10. list.add("stormy");
  11. list.add("night");
  12. 4.
  13. List.add(3, “dark”);
  14. List.add(4, “and”);
  15. 5.
  16. list.set(1, “IS”);
  17. 6.
  18. For(int x = 0; x < list.size(); x++)
  19. {
  20. If(list.get(x).indexOf(“a”) >= 0)
  21. {
  22. List.remove(x);
  23. x--;
  24. }
  25. }
  26.  
  27. 7.
  28. ArrayList <Integer> num = new ArrayList <Integer>();
  29. For(int x = 0; x < 10; x++)
  30. {numbers.add(2*x);}
  31. 8.
  32. Public static int maxLength (ArrayList<String> list)
  33. {
  34. Int max = 0;
  35. For(int x = 0; x < list.size(); x++)
  36. {
  37. String n = list.get(x);
  38. If(n.length() > max)
  39. {
  40. Max = n.length();
  41. }
  42. }
  43. }
  44. 9.
  45. System.out.println (list.contains(“IS”));
  46. 10.
  47. System.out.println (list.indexOf(“stormy”));
  48. System.out.println (list.indexOf(“dark”));
  49. 11.
  50. for(int x = 0; x < list.size(); x++)
  51. {System.out.println (n.toUpperCase());
  52. 12. throws a ConcurrentModificationException
  53. 13. use integer instead of int when declaring the new arraylist
  54. 14.
  55. Wrapper class: class with the purpose of bridging primitive values and objects
  56. Integer: object that holds int value
  57. Int: primitive value type
  58. 15.
  59. a. [1, 2, 6, 8]
  60. b. [10, 30, 40, 20, 60, 50]
  61. c. [-4, 1, 25, 4, 16, 9, 64, 36, 49]
  62. 16.
  63. a. [20, 10, 20, 30, 30, 20]
  64. b. [8, 7, 8, 2, 9, 7, 4, 4, 2, 8]
  65. c. [33, 28, 33, -1, 3, 28, 17, 9, 33, 17, -1, 33]
  66. 17.
  67. a.[72,20]
  68. b. [1, 20, 18, 15, 11, 6]
  69. c. [10, 90, 70, 40]
  70. 18.
  71. a. [31, 21, 11]
  72. b. [5, 8, 10, 3, 9]
  73. c. [34, 10, 18, 29, 4, 0]
Advertisement
Add Comment
Please, Sign In to add comment