View RSS Feed


A little on Containers. ( Collections + Maps )

Rating: 1 votes, 1.00 average.
by , 02-07-2012 at 08:39 PM (1493 Views)
Java Code:
package myPaackkage;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.TreeSet;

public class PrintingContainers {
	static Collection<String> fill(Collection<String> collection) {
		return collection;
	static Map fill(Map<String,String> map)
		map.put("Koray", "Pinar");
		map.put("Bahtiyar", "Melike");
		map.put("Onur", "Pinar");
		map.put("Cem", "Nergis");
		return map;
	public static void main(String[] args)
		System.out.println("Array List: " + PrintingContainers.fill(new ArrayList<String>()));
		System.out.println("Linked List: " + PrintingContainers.fill(new LinkedList<String>()));
		System.out.println("HashSet: " + PrintingContainers.fill(new HashSet<String>()));
		System.out.println("TreeSet: " + PrintingContainers.fill(new TreeSet<String>()));
		System.out.println("LinkedHashSet: " + PrintingContainers.fill(new LinkedHashSet<String>()));
		System.out.println("HashMap: " + PrintingContainers.fill(new HashMap<String,String>()));
		System.out.println("TreeMap: " + PrintingContainers.fill(new TreeMap<String,String>()));
		System.out.println("LinkedHashMap" + PrintingContainers.fill(new LinkedHashMap<String,String>()));

Array List: [rat, cat, dog, dog]
Linked List: [rat, cat, dog, dog]
HashSet: [cat, dog, rat]
TreeSet: [cat, dog, rat]
LinkedHashSet: [rat, cat, dog]
HashMap: {Onur=Pinar, Bahtiyar=Melike, Cem=Nergis, Koray=Pinar}
TreeMap: {Bahtiyar=Melike, Cem=Nergis, Koray=Pinar, Onur=Pinar}
LinkedHashMap{Koray=Pinar, Bahtiyar=Melike, Onur=Pinar, Cem=Nergis}

Submit "A little on Containers. ( Collections + Maps )" to Facebook Submit "A little on Containers. ( Collections + Maps )" to Digg Submit "A little on Containers. ( Collections + Maps )" to Submit "A little on Containers. ( Collections + Maps )" to StumbleUpon Submit "A little on Containers. ( Collections + Maps )" to Google

Tags: None Add / Edit Tags