Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- public class arrayList
- {
- public static void main (String args []){
- ArrayList <Integer> myList = new ArrayList <Integer>(10);
- myList.add(199);
- myList.add(4);
- myList.add(100);
- myList.add(555);
- myList.add(40);
- myList.add(49);
- for (Integer x : myList){
- System.out.println(x);
- }
- //size does not indicate the intitial size only the amount of items stored
- System.out.println("size="+myList.size());
- myList.remove(1);
- //size does not indicate the intitial size only the amount of items stored
- System.out.println("size="+myList.size());
- myList.set(1, 50);//myList.set(index, value), changes value of index in the ArrayList
- /* trims the size of the arrayList to how many items are stored
- * if the initial size was 10 but there were 6 items stored the
- * trimToSize method would reduce the initial size to 6.
- * */
- myList.trimToSize();
- myList.clear();//clears the contents of the arrayList
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment