Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1.
- 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.
- 2.
- e.
- 3.
- ArrayList<String> list = new ArrayList<String>();
- list.add("It");
- list.add("was");
- list.add("a");
- list.add("stormy");
- list.add("night");
- 4.
- List.add(3, “dark”);
- List.add(4, “and”);
- 5.
- list.set(1, “IS”);
- 6.
- For(int x = 0; x < list.size(); x++)
- {
- If(list.get(x).indexOf(“a”) >= 0)
- {
- List.remove(x);
- x--;
- }
- }
- 7.
- ArrayList <Integer> num = new ArrayList <Integer>();
- For(int x = 0; x < 10; x++)
- {numbers.add(2*x);}
- 8.
- Public static int maxLength (ArrayList<String> list)
- {
- Int max = 0;
- For(int x = 0; x < list.size(); x++)
- {
- String n = list.get(x);
- If(n.length() > max)
- {
- Max = n.length();
- }
- }
- }
- 9.
- System.out.println (list.contains(“IS”));
- 10.
- System.out.println (list.indexOf(“stormy”));
- System.out.println (list.indexOf(“dark”));
- 11.
- for(int x = 0; x < list.size(); x++)
- {System.out.println (n.toUpperCase());
- 12. throws a ConcurrentModificationException
- 13. use integer instead of int when declaring the new arraylist
- 14.
- Wrapper class: class with the purpose of bridging primitive values and objects
- Integer: object that holds int value
- Int: primitive value type
- 15.
- a. [1, 2, 6, 8]
- b. [10, 30, 40, 20, 60, 50]
- c. [-4, 1, 25, 4, 16, 9, 64, 36, 49]
- 16.
- a. [20, 10, 20, 30, 30, 20]
- b. [8, 7, 8, 2, 9, 7, 4, 4, 2, 8]
- c. [33, 28, 33, -1, 3, 28, 17, 9, 33, 17, -1, 33]
- 17.
- a.[72,20]
- b. [1, 20, 18, 15, 11, 6]
- c. [10, 90, 70, 40]
- 18.
- a. [31, 21, 11]
- b. [5, 8, 10, 3, 9]
- c. [34, 10, 18, 29, 4, 0]
Advertisement
Add Comment
Please, Sign In to add comment