Specifications

Sun Services
Java™ Programming Language
Module 9, slide 28 of 37
Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision F
A List Example
1 import java.util.*
2
3 public class ListExample {
4 public static void main(String[] args) {
5 List list = new ArrayList();
6 list.add("one");
7 list.add("second");
8 list.add("3rd");
9 list.add(new Integer(4));
10 list.add(new Float(5.0F));
11 list.add("second"); // duplicate, is added
12 list.add(new Integer(4)); // duplicate, is added
13 System.out.println(list);
14 }
15 }
The output generated from this program is:
[one, second, 3rd, 4, 5.0, second, 4]