Demonstrate ArrayList

import java.util.*;

class ArrayListDemo {
public static void main(String args[]) {
// Create an array list.
ArrayList<String> al = new ArrayList<String>();

System.out.println(“Initial size of al: ” +
al.size());
// Add elements to the array list.
al.add(“C”);
al.add(“A”);
al.add(“E”);
al.add(“B”);
al.add(“D”);
al.add(“F”);
al.add(1, “A2″);

System.out.println(“Size of al after additions: ” +
al.size());

// Display the array list.
System.out.println(“Contents of al: ” + al);

// Remove elements from the array list.
al.remove(“F”);
al.remove(2);

System.out.println(“Size of al after deletions: ” +
al.size());

System.out.println(“Contents of al: ” + al);
}
}

Advertisements

About qainterviews

Software Geek,QA Expert,Blogger
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s