torsdag 31 maj 2012

ArrayList

Lecture 17 - ArrayList.

ArrayList is an object. The actual size equals (almost all the times) the effective size.
import java.util.*;

ArrayList<String> slist = new ArrayList<String>( ); //an arraylist of strings

An arraylist holds objects. You can't use primitve types as int, double etc. However you can use the wrapperclass; Integer, Double, Boolean, Character. Notice: They are immuntable, just like Strings, which means that you can't change them. You have to create a new one and override the old one.

But when you write your code you can write like this:

ArrayList<Integer> ilist = new <Integer>( );
   int x = 5;
   ilist.add(x);
   int z = ilist.get(0);