ArrayList copy and shallow copy
In this chapter you will learn:
Shallow copy of current ArrayList
Object clone()
Returns a shallow copy of this ArrayList instance.
import java.util.ArrayList;
import java.util.List;
// j a va 2 s . c o m
public class Main {
public static void main(String args[]) {
ArrayList<String> al = new ArrayList<String>();
al.add("C");
al.add("A");
al.add("E");
al.add("java2s.com");
al.add("D");
al.add("F");
al.add(1, "java2s.com");
System.out.println(al);
Object list = al.clone();
System.out.println(list);
}
}
The output:
Next chapter...
What you will learn in the next chapter:
- How to increases the capacity of an ArrayList
- How to get the size and trim to size for an ArrayList
- If ArrayList is empty
Home » Java Tutorial » Collections