Java collection

JAVA COLLECTION

Java Collection is a framework that provides many fundamental features like ArrayList, LinkedList, HashTable, HashMap etc. It provides set of Interfaces.

Sample Example of Collection :

package collection;

import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;

//This code contains the use of  
                                         Iterator class.
public class CollectionIterator {
	
	public static void main(String s[]){

		List<String> allList = new ArrayList<String>();
		allList.add("String");
		allList.add("Polymorphism");
		allList.add("Threading");
		allList.add("Struts");
		System.out.println(allList);
		
		Iterator<String> itr = allList.iterator();
		while(itr.hasNext()){
			System.out.println(itr.next());
		}
	}
	
}

Output

[String, Polymorphism, Threading, Struts]
String
Polymorphism
Threading
Struts

 

NEXT PAGE

Facebooktwittergoogle_plusredditpinterestlinkedinmail
1 Star2 Stars3 Stars4 Stars5 Stars (8 votes, average: 5.00 out of 5)
Loading...