Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
ArrayList Basics
java.util.ArrayList class is one of the most
commonly used classes in the Collections
Framework.
Advantages that ArrayList has over arrays are
It can grow dynamically.
It provides more powerful insertion and
search mechanisms than arrays.
ArrayList Basics
Instantiation:
List myList = new ArrayList();
For an ArrayList of Strings (followed in Java 5)
List<String> myList = new ArrayList<String>();
Prior to Java 5, there was no way to specify the type of
a collection
class UseBoxing {
public static void main(String [] args) {
UseBoxing u = new UseBoxing();
u.go(5);
}
boolean go(Integer i) { // boxes the int it was passed
Boolean ifSo = true; // boxes the literal
Short s = 300;
// boxes the primitive
if(ifSo) { // unboxing
System.out.println(++s); // unboxes, increments, reboxes
}
return !ifSo; // unboxes, returns the inverse
}
}