Step 21:Collection Frameworks -14th+15th hour + code

Collection

Dynamic data structure to store and manipulating group of elements.

Collections Framework

It’s a architecture for representing and manipulating collections.

In java, collection framework includes 3 things-

-(a)interfaces
-(b)implemented classes
-(c)algorithms

Collections Hierarchy –

colfrmwrk

Ordered:

When a collection is ordered, it means you can iterate through the collection in a specific (not-random) order

Sorted:

A sorted collection means that the order of objects in the collection is determined according to some rule or rules, known as the sorting order.

Important :

1- Hashmap

It’s not synchronized so can’t be used in multi-threaded environment.
-it fail-fast.
Note – Equals and hashCode contract in Java

And equals method in Java must follow its contract with hashcode method in Java as stated below.
1) If two objects are equal by equals() method then there hashcode must be same.
2) If two objects are not equal by equals() method then there hashcode could be same or different.

2SynchronizedHasmap

Entire hashmap in synchronized.
– Every read and write aquires lock, hence decrease the performance.

3- Hashtable

It’s similar to synchronizedHashmap, but it just legacy class.

4ConcurrentHashmap

It’s threadSafe hashmap.
– All read without lock and write with lock, so gives better performance in more reader, less writer scenario.
– Lock is applied on portion of hashmap-buckets, which is called segments.
– by default there are 16 segements and 16 threads.
– it’s a fail-safe.

Difference in internal structure -concurrentHashmap

1- It adds additional array on the top of bucket/array indexes of hashmap, which is called segments.
2- Each index points to copy of entire hashmap.

Instance of concurrent hashmap have 3 things.

new ConcurrentHashMap(initialCapacity, LoadFactor, ConcurrencyLevel);

a- initial Capacity (by default is 16)
b- load Factor (by default is 0.75f)
c- Concurrency Level (by default is 16)

Note – Segments = 2^x >=Concurrency Level(numbers of threads)

Note –

Fail-fast vs fail-safe

1- fail-fast-

When we iterate through the collection, it throws exception if any change occurs in internal structure of collection. for example- Hashmap

2- fail-safe-

It uses a copy of internal structure of collection, so changes are performed on this internal structure, rather than original collection. Doesn’t throw any exception. for example- Concurrent Hashmap

code samples are here

1- Arraylist : creation and iteration using Iterator

package CollectionFramework;

import java.util.*;
public class ExArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}
2- Arraylist : creation and iteration using ListIterator
package CollectionFramework;

import java.util.*;
public class ExArrList2 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

ListIterator listItr=collDemo.listIterator();

while(listIterator.hasNext()){
System.out.println("using listinterator : next: "+listIterator.next());
}

while(listIterator.hasPrevious()){
System.out.println("using listinterator : previous: "+listIterator.previous());
}
}
}

3- Arraylist : creation and iteration using ForEach

package CollectionFramework;

import java.util.*;
public class ExArrList3 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);
for (Integer i : collDemo) {
System.out.println(i);
}
}
} 

4- LinkedList : creation and iteration using Iterator

package CollectionFramework;

import java.util.*;
public class ExLinkList1 {

public static void main(String[] args) {
List collDemo=new LinkedList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);
Iterator itr=collDemo.iterator();

while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
} 

5- LinkedList : creation and iteration using ListIterator

package CollectionFramework;

import java.util.*;
public class ExLinkList1 {

public static void main(String[] args) {
List collDemo=new LinkedList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);
ListIterator listItr=collDemo.listIterator();

while(listIterator.hasNext()){
System.out.println("using listinterator : next: "+listIterator.next());
}

while(listIterator.hasPrevious()){
System.out.println("using listinterator : previous: "+listIterator.previous());
}
}
} 

6- LinkedList : creation and iteration using ForEach

package CollectionFramework;

import java.util.*;
public class ExLinkList1 {

public static void main(String[] args) {
List collDemo=new LinkedList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);
for (Integer i : collDemo) {
System.out.println(i);
}
}
} 
7-Vector : creation and iteration using Iterator
package CollectionFramework;

import java.util.*;
public class ExVector1 {

public static void main(String[] args) {
List collDemo=new Vector();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Iterator itr=collDemo.iterator();

while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
} 

8-Vector : creation and iteration using ListIterator

package CollectionFramework;

import java.util.*;
public class ExVector2 {

public static void main(String[] args) {
List collDemo=new Vector();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);
ListIterator listItr=collDemo.listIterator();

while(listIterator.hasNext()){
System.out.println("using listinterator : next: "+listIterator.next());
}

while(listIterator.hasPrevious()){
System.out.println("using listinterator : previous: "+listIterator.previous());
}
}
} 
9- Vector : creation and iteration using ForEach
package CollectionFramework;

import java.util.*;
public class ExVector3 {

public static void main(String[] args) {
List collDemo=new Vector();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);
for (Integer i : collDemo) {
System.out.println(i);
}
}
} 
1-HashSet: Creation and Iteration using Iterator
package CollectionFramework;
import java.util.*;
public class ExHashset1 {

public static void main(String[] args) {
Set collDemo=new HashSet();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);
Iterator itr=collDemo.iterator();

while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
} 
2-LinkedHashSet: Creation and Iteration using Iterator
package CollectionFramework;
import java.util.*;
public class ExLinkHashset1 {

public static void main(String[] args) {
Set collDemo=new LinkedHashSet();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);
Iterator itr=collDemo.iterator();

while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
} 

3- TreeSet: Creation and Iteration using Iterator

package CollectionFramework;
import java.util.*;
public class ExLinkHashset1 {

public static void main(String[] args) {
Set collDemo=new LinkedHashSet();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);
Iterator itr=collDemo.iterator();

while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
} 
1- PriorityQueue: creation and iteration using Iterator
package CollectionFramework;

import java.util.*;
public class ExPrQue1 {

public static void main(String[] args) {
Queue collDemo=new PriorityQueue();
collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);
Iterator itr=collDemo.iterator();

while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
} 

2– PriorityQueue: creation and iteration using ForEach

package CollectionFramework;

import java.util.*;
public class ExPrQue2 {

public static void main(String[] args) {
Queue collDemo=new PriorityQueue();
collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

for (Integer i : collDemo) {
System.out.println(i);
}
}
} 
1- ArrayDeque : creation and iteration using Iterator
package CollectionFramework;

import java.util.*;
public class ExArrDQue1 {

public static void main(String[] args) {
Queue collDemo=new ArrayDeque();
collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);
Iterator itr=collDemo.iterator();

while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
} 
2- ArrayDeque : creation and iteration using ForEach
package CollectionFramework;

import java.util.*;
public class ExArrDQue2 {

public static void main(String[] args) {
Queue collDemo=new ArrayDeque();
collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);
for (Integer i : collDemo) {
System.out.println(i);
}
}
} 

1- Hashmap : creation and iteration using Iterator

 
package CollectionFramework; 
import java.util.*; 
public class ExHashmap { 
public static void main(String[] args) { 
Map colldemoMap=new HashMap(); 
colldemoMap.put("Key1","Value1"); 
colldemoMap.put("key2","Value2"); 
colldemoMap.put("key3","Value3"); 
Iterator iterator=colldemoMap.keySet().iterator(); 
while(iterator.hasNext()){ 
String key=iterator.next().toString(); 
String value=colldemoMap.get(key); 
System.out.println(key); 
System.out.println(value); 
} 
} 
} 
2- Hashmap : creation and iteration using ForEach
package CollectionFramework;

import java.util.*;

public class ExHashmap {

public static void main(String[] args) {

Map colldemoMap=new HashMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");

for(Object key : colldemoMap.keySet()){
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 
1- LinkedHashmap : creation and iteration using Iterator
package CollectionFramework;

import java.util.*;

public class ExLinkHashmap1 {

public static void main(String[] args) {
Map colldemoMap=new LinkedHashMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");
Iterator iterator=colldemoMap.keySet().iterator();
while(iterator.hasNext()){
String key=iterator.next().toString();
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 
2- LinkedHashmap : creation and iteration using ForEach
package CollectionFramework;

import java.util.*;

public class ExLinkHashmap2 {

public static void main(String[] args) {

Map colldemoMap=new LinkedHashMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");

for(Object key : colldemoMap.keySet()){
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

1- Treemap : creation and iteration using Iterator

package CollectionFramework;

import java.util.*;

public class ExTreeHashmap1 {

public static void main(String[] args) {
Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");
Iterator iterator=colldemoMap.keySet().iterator();
while(iterator.hasNext()){
String key=iterator.next().toString();
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 
2- Treemap : creation and iteration using ForEach
package CollectionFramework;

import java.util.*;

public class ExTreeHashmap2 {

public static void main(String[] args) {

Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");

for(Object key : colldemoMap.keySet()){
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

1- Sorting a collection

package CollectionFramework;

import java.util.*;
public class ExsortArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.sort(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

2- Searching in collection

package CollectionFramework;

import java.util.*;
public class ExsearchingArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);
<pre>Collections.sort(collDemo);
</pre>
<pre>int i = Collections.binarySearch(collDemo,12); 

System.out.println("position of element is ");
System.out.println(i);
}
} 

3- Shuffling a collection

package CollectionFramework;


import java.util.*;
public class ExshuffleArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.shuffle(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

4– Reversing a collection

package CollectionFramework;


import java.util.*;
public class ExreverseArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.reverse(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}
1- ArrayDeque : creation and iteration using Iterator
package CollectionFramework;


import java.util.*;
public class ExArrDQue1 {

public static void main(String[] args) {
Queue collDemo=new ArrayDeque();
collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);
Iterator itr=collDemo.iterator(); 

while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
} 

2- ArrayDeque : creation and iteration using ForEach
package CollectionFramework;

import java.util.*;
public class ExArrDQue2 {

public static void main(String[] args) {
Queue collDemo=new ArrayDeque();
collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);
for (Integer i : collDemo) {
System.out.println(i);
}
}
} 

1- Hashmap : creation and iteration using Iterator

package CollectionFramework;

import java.util.*;

public class ExHashmap {

public static void main(String[] args) {
Map colldemoMap=new HashMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");
Iterator iterator=colldemoMap.keySet().iterator();
while(iterator.hasNext()){
String key=iterator.next().toString();
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 
2- Hashmap : creation and iteration using ForEach
package CollectionFramework;

import java.util.*;

public class ExHashmap {

public static void main(String[] args) {

Map colldemoMap=new HashMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");

for(Object key : colldemoMap.keySet()){
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 
1- LinkedHashmap : creation and iteration using Iterator
package CollectionFramework;

import java.util.*;

public class ExLinkHashmap1 {

public static void main(String[] args) {
Map colldemoMap=new LinkedHashMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");
Iterator iterator=colldemoMap.keySet().iterator();
while(iterator.hasNext()){
String key=iterator.next().toString();
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 
2- LinkedHashmap : creation and iteration using ForEach
package CollectionFramework;

import java.util.*;

public class ExLinkHashmap2 {

public static void main(String[] args) {

Map colldemoMap=new LinkedHashMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");

for(Object key : colldemoMap.keySet()){
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

1- Treemap : creation and iteration using Iterator

package CollectionFramework;

import java.util.*;

public class ExTreeHashmap1 {

public static void main(String[] args) {
Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");
Iterator iterator=colldemoMap.keySet().iterator();
while(iterator.hasNext()){
String key=iterator.next().toString();
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 
2- Treemap : creation and iteration using ForEach
package CollectionFramework;

import java.util.*;

public class ExTreeHashmap2 {

public static void main(String[] args) {

Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");

for(Object key : colldemoMap.keySet()){
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

1- Sorting a collection

package CollectionFramework;

import java.util.*;
public class ExsortArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.sort(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

2- Searching in collection

package CollectionFramework;

import java.util.*;
public class ExsearchingArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);
<pre>Collections.sort(collDemo);
</pre>
<pre>int i = Collections.binarySearch(collDemo,12);

System.out.println("position of element is ");
System.out.println(i);
}
} 

3- Shuffling a collection

package CollectionFramework;

import java.util.*;
public class ExshuffleArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.shuffle(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

4– Reversing a collection

package CollectionFramework;

import java.util.*;
public class ExreverseArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.reverse(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}
1- LinkedHashmap : creation and iteration using Iterator
package CollectionFramework;


import java.util.*;

public class ExLinkHashmap1 {

public static void main(String[] args) {
Map colldemoMap=new LinkedHashMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");
Iterator iterator=colldemoMap.keySet().iterator();
while(iterator.hasNext()){
String key=iterator.next().toString();
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 
2- LinkedHashmap : creation and iteration using ForEach
package CollectionFramework;


import java.util.*;

public class ExLinkHashmap2 {

public static void main(String[] args) {

Map colldemoMap=new LinkedHashMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");

for(Object key : colldemoMap.keySet()){
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

1- Treemap : creation and iteration using Iterator

package CollectionFramework;

import java.util.*;

public class ExTreeHashmap1 {

public static void main(String[] args) {
Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");
Iterator iterator=colldemoMap.keySet().iterator();
while(iterator.hasNext()){
String key=iterator.next().toString();
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 
2- Treemap : creation and iteration using ForEach
package CollectionFramework;


import java.util.*;

public class ExTreeHashmap2 {

public static void main(String[] args) {

Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");

for(Object key : colldemoMap.keySet()){
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

1- Sorting a collection

package CollectionFramework;

import java.util.*;
public class ExsortArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.sort(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

2- Searching in collection

package CollectionFramework;

import java.util.*;
public class ExsearchingArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);
<pre>Collections.sort(collDemo);
</pre>
<pre>int i = Collections.binarySearch(collDemo,12);

System.out.println("position of element is ");
System.out.println(i);
}
} 

3- Shuffling a collection

package CollectionFramework;

import java.util.*;
public class ExshuffleArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.shuffle(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

4– Reversing a collection

package CollectionFramework;

import java.util.*;
public class ExreverseArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.reverse(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}
1- PriorityQueue: creation and iteration using Iterator
package CollectionFramework;


import java.util.*;
public class ExPrQue1 {

public static void main(String[] args) {
Queue collDemo=new PriorityQueue();
collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);
Iterator itr=collDemo.iterator();

while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
} 

2– PriorityQueue: creation and iteration using ForEach

package CollectionFramework;

import java.util.*;
public class ExPrQue2 {

public static void main(String[] args) {
Queue collDemo=new PriorityQueue();
collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

for (Integer i : collDemo) {
System.out.println(i);
}
}
} 
1- ArrayDeque : creation and iteration using Iterator
package CollectionFramework;

import java.util.*;
public class ExArrDQue1 {

public static void main(String[] args) {
Queue collDemo=new ArrayDeque();
collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);
Iterator itr=collDemo.iterator();

while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
} 
2- ArrayDeque : creation and iteration using ForEach
package CollectionFramework;

import java.util.*;
public class ExArrDQue2 {

public static void main(String[] args) {
Queue collDemo=new ArrayDeque();
collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);
for (Integer i : collDemo) {
System.out.println(i);
}
}
} 

1- Hashmap : creation and iteration using Iterator

package CollectionFramework;

import java.util.*;

public class ExHashmap {

public static void main(String[] args) {
Map colldemoMap=new HashMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");
Iterator iterator=colldemoMap.keySet().iterator();
while(iterator.hasNext()){
String key=iterator.next().toString();
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 
2- Hashmap : creation and iteration using ForEach
package CollectionFramework;

import java.util.*;

public class ExHashmap {

public static void main(String[] args) {

Map colldemoMap=new HashMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");

for(Object key : colldemoMap.keySet()){
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 
1- LinkedHashmap : creation and iteration using Iterator
package CollectionFramework;

import java.util.*;

public class ExLinkHashmap1 {

public static void main(String[] args) {
Map colldemoMap=new LinkedHashMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");
Iterator iterator=colldemoMap.keySet().iterator();
while(iterator.hasNext()){
String key=iterator.next().toString();
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 
2- LinkedHashmap : creation and iteration using ForEach
package CollectionFramework;

import java.util.*;

public class ExLinkHashmap2 {

public static void main(String[] args) {

Map colldemoMap=new LinkedHashMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");

for(Object key : colldemoMap.keySet()){
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

1- Treemap : creation and iteration using Iterator

package CollectionFramework;

import java.util.*;

public class ExTreeHashmap1 {

public static void main(String[] args) {
Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");
Iterator iterator=colldemoMap.keySet().iterator();
while(iterator.hasNext()){
String key=iterator.next().toString();
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 
2- Treemap : creation and iteration using ForEach
package CollectionFramework;

import java.util.*;

public class ExTreeHashmap2 {

public static void main(String[] args) {

Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");

for(Object key : colldemoMap.keySet()){
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

1- Sorting a collection

package CollectionFramework;

import java.util.*;
public class ExsortArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.sort(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

2- Searching in collection

package CollectionFramework;

import java.util.*;
public class ExsearchingArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);
<pre>Collections.sort(collDemo);
</pre>
<pre>int i = Collections.binarySearch(collDemo,12);

System.out.println("position of element is ");
System.out.println(i);
}
} 

3- Shuffling a collection

package CollectionFramework;

import java.util.*;
public class ExshuffleArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.shuffle(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

4– Reversing a collection

package CollectionFramework;

import java.util.*;
public class ExreverseArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.reverse(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

1- Treemap : creation and iteration using Iterator

package CollectionFramework;

import java.util.*;

public class ExTreeHashmap1 {

public static void main(String[] args) {
Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");
Iterator iterator=colldemoMap.keySet().iterator();
while(iterator.hasNext()){
String key=iterator.next().toString();
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

2- Treemap : creation and iteration using ForEach

package CollectionFramework;

import java.util.*;

public class ExTreeHashmap2 {

public static void main(String[] args) {

Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");

for(Object key : colldemoMap.keySet()){
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

1- Sorting a collection

package CollectionFramework;

import java.util.*;
public class ExsortArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.sort(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

2- Searching in collection

package CollectionFramework;

import java.util.*;
public class ExsearchingArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);</pre>
<pre>Collections.sort(collDemo);
</pre>
<pre>int i = Collections.binarySearch(collDemo,12);

System.out.println("position of element is ");
System.out.println(i);
}
} 

3- Shuffling a collection

package CollectionFramework;

import java.util.*;
public class ExshuffleArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.shuffle(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

4– Reversing a collection

package CollectionFramework;

import java.util.*;
public class ExreverseArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.reverse(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

1- LinkedHashmap : creation and iteration using Iterator

package CollectionFramework;

import java.util.*;

public class ExLinkHashmap1 {

public static void main(String[] args) {
Map colldemoMap=new LinkedHashMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");
Iterator iterator=colldemoMap.keySet().iterator();
while(iterator.hasNext()){
String key=iterator.next().toString();
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 
2- LinkedHashmap : creation and iteration using ForEach
package CollectionFramework;


import java.util.*;

public class ExLinkHashmap2 {

public static void main(String[] args) {

Map colldemoMap=new LinkedHashMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");

for(Object key : colldemoMap.keySet()){
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

1- Treemap : creation and iteration using Iterator

package CollectionFramework;

import java.util.*;

public class ExTreeHashmap1 {

public static void main(String[] args) {
Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");
Iterator iterator=colldemoMap.keySet().iterator();
while(iterator.hasNext()){
String key=iterator.next().toString();
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 
2- Treemap : creation and iteration using ForEach
package CollectionFramework;


import java.util.*;

public class ExTreeHashmap2 {

public static void main(String[] args) {

Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");

for(Object key : colldemoMap.keySet()){
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

1- Sorting a collection

package CollectionFramework;

import java.util.*;
public class ExsortArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.sort(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

2- Searching in collection

package CollectionFramework;

import java.util.*;
public class ExsearchingArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);
<pre>Collections.sort(collDemo);
</pre>
<pre>int i = Collections.binarySearch(collDemo,12);

System.out.println("position of element is ");
System.out.println(i);
}
} 

3- Shuffling a collection

package CollectionFramework;

import java.util.*;
public class ExshuffleArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.shuffle(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

4– Reversing a collection

package CollectionFramework;

import java.util.*;
public class ExreverseArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.reverse(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

1- Treemap : creation and iteration using Iterator

package CollectionFramework;

import java.util.*;

public class ExTreeHashmap1 {

public static void main(String[] args) {
Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");
Iterator iterator=colldemoMap.keySet().iterator();
while(iterator.hasNext()){
String key=iterator.next().toString();
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

2- Treemap : creation and iteration using ForEach

package CollectionFramework;

import java.util.*;

public class ExTreeHashmap2 {

public static void main(String[] args) {

Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");

for(Object key : colldemoMap.keySet()){
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

1- Sorting a collection

package CollectionFramework;

import java.util.*;
public class ExsortArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.sort(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

2- Searching in collection

package CollectionFramework;

import java.util.*;
public class ExsearchingArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);</pre>
<pre>Collections.sort(collDemo);
</pre>
<pre>int i = Collections.binarySearch(collDemo,12);

System.out.println("position of element is ");
System.out.println(i);
}
} 

3- Shuffling a collection

package CollectionFramework;

import java.util.*;
public class ExshuffleArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.shuffle(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

4– Reversing a collection

package CollectionFramework;

import java.util.*;
public class ExreverseArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.reverse(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

1- Treemap : creation and iteration using Iterator

package CollectionFramework;

import java.util.*;

public class ExTreeHashmap1 {

public static void main(String[] args) {
Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");
Iterator iterator=colldemoMap.keySet().iterator();
while(iterator.hasNext()){
String key=iterator.next().toString();
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

2- Treemap : creation and iteration using ForEach

package CollectionFramework;

import java.util.*;

public class ExTreeHashmap2 {

public static void main(String[] args) {

Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");

for(Object key : colldemoMap.keySet()){
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

1- Sorting a collection

package CollectionFramework;

import java.util.*;
public class ExsortArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.sort(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

2- Searching in collection

package CollectionFramework;

import java.util.*;
public class ExsearchingArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);</pre>
<pre>Collections.sort(collDemo);
</pre>
<pre>int i = Collections.binarySearch(collDemo,12);

System.out.println("position of element is ");
System.out.println(i);
}
} 

3- Shuffling a collection

package CollectionFramework;

import java.util.*;
public class ExshuffleArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.shuffle(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

4– Reversing a collection

package CollectionFramework;

import java.util.*;
public class ExreverseArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.reverse(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

1- LinkedHashmap : creation and iteration using Iterator

package CollectionFramework;

import java.util.*;

public class ExLinkHashmap1 {

public static void main(String[] args) {
Map colldemoMap=new LinkedHashMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");
Iterator iterator=colldemoMap.keySet().iterator();
while(iterator.hasNext()){
String key=iterator.next().toString();
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

2- LinkedHashmap : creation and iteration using ForEach

package CollectionFramework;

import java.util.*;

public class ExLinkHashmap2 {

public static void main(String[] args) {

Map colldemoMap=new LinkedHashMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");

for(Object key : colldemoMap.keySet()){
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

1- Treemap : creation and iteration using Iterator

package CollectionFramework;

import java.util.*;

public class ExTreeHashmap1 {

public static void main(String[] args) {
Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");
Iterator iterator=colldemoMap.keySet().iterator();
while(iterator.hasNext()){
String key=iterator.next().toString();
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

2- Treemap : creation and iteration using ForEach

package CollectionFramework;

import java.util.*;

public class ExTreeHashmap2 {

public static void main(String[] args) {

Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");

for(Object key : colldemoMap.keySet()){
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

1- Sorting a collection

package CollectionFramework;

import java.util.*;
public class ExsortArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.sort(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

2- Searching in collection

package CollectionFramework;

import java.util.*;
public class ExsearchingArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);</pre>
<pre>Collections.sort(collDemo);
</pre>
<pre>int i = Collections.binarySearch(collDemo,12);

System.out.println("position of element is ");
System.out.println(i);
}
} 

3- Shuffling a collection

package CollectionFramework;

import java.util.*;
public class ExshuffleArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.shuffle(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

4– Reversing a collection

package CollectionFramework;

import java.util.*;
public class ExreverseArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.reverse(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

1- Treemap : creation and iteration using Iterator

package CollectionFramework;

import java.util.*;

public class ExTreeHashmap1 {

public static void main(String[] args) {
Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");
Iterator iterator=colldemoMap.keySet().iterator();
while(iterator.hasNext()){
String key=iterator.next().toString();
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

2- Treemap : creation and iteration using ForEach

package CollectionFramework;

import java.util.*;

public class ExTreeHashmap2 {

public static void main(String[] args) {

Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");

for(Object key : colldemoMap.keySet()){
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

1- Sorting a collection

package CollectionFramework;

import java.util.*;
public class ExsortArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.sort(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

2- Searching in collection

package CollectionFramework;

import java.util.*;
public class ExsearchingArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);</pre>
<pre>Collections.sort(collDemo);
</pre>
<pre>int i = Collections.binarySearch(collDemo,12);

System.out.println("position of element is ");
System.out.println(i);
}
} 

3- Shuffling a collection

package CollectionFramework;

import java.util.*;
public class ExshuffleArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.shuffle(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

4– Reversing a collection

package CollectionFramework;

import java.util.*;
public class ExreverseArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.reverse(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

1- Treemap : creation and iteration using Iterator

package CollectionFramework;

import java.util.*;

public class ExTreeHashmap1 {

public static void main(String[] args) {
Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");
Iterator iterator=colldemoMap.keySet().iterator();
while(iterator.hasNext()){
String key=iterator.next().toString();
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

2- Treemap : creation and iteration using ForEach

package CollectionFramework;

import java.util.*;

public class ExTreeHashmap2 {

public static void main(String[] args) {

Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");

for(Object key : colldemoMap.keySet()){
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

1- Sorting a collection

package CollectionFramework;

import java.util.*;
public class ExsortArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.sort(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

2- Searching in collection

package CollectionFramework;

import java.util.*;
public class ExsearchingArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);</pre>
<pre>Collections.sort(collDemo);
</pre>
<pre>int i = Collections.binarySearch(collDemo,12);

System.out.println("position of element is ");
System.out.println(i);
}
} 

3- Shuffling a collection

package CollectionFramework;

import java.util.*;
public class ExshuffleArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.shuffle(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

4– Reversing a collection

package CollectionFramework;

import java.util.*;
public class ExreverseArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.reverse(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}
1- LinkedHashmap : creation and iteration using Iterator
package CollectionFramework;


import java.util.*;

public class ExLinkHashmap1 {

public static void main(String[] args) {
Map colldemoMap=new LinkedHashMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");
Iterator iterator=colldemoMap.keySet().iterator();
while(iterator.hasNext()){
String key=iterator.next().toString();
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

2- LinkedHashmap : creation and iteration using ForEach

package CollectionFramework;

import java.util.*;

public class ExLinkHashmap2 {

public static void main(String[] args) {

Map colldemoMap=new LinkedHashMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");

for(Object key : colldemoMap.keySet()){
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

1- Treemap : creation and iteration using Iterator

package CollectionFramework;

import java.util.*;

public class ExTreeHashmap1 {

public static void main(String[] args) {
Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");
Iterator iterator=colldemoMap.keySet().iterator();
while(iterator.hasNext()){
String key=iterator.next().toString();
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

2- Treemap : creation and iteration using ForEach

package CollectionFramework;

import java.util.*;

public class ExTreeHashmap2 {

public static void main(String[] args) {

Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");

for(Object key : colldemoMap.keySet()){
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

1- Sorting a collection

package CollectionFramework;

import java.util.*;
public class ExsortArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.sort(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

2- Searching in collection

package CollectionFramework;

import java.util.*;
public class ExsearchingArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);
<pre>Collections.sort(collDemo);
</pre>
<pre>int i = Collections.binarySearch(collDemo,12);

System.out.println("position of element is ");
System.out.println(i);
}
} 

3- Shuffling a collection

package CollectionFramework;

import java.util.*;
public class ExshuffleArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.shuffle(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

4– Reversing a collection

package CollectionFramework;

import java.util.*;
public class ExreverseArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.reverse(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

1- Treemap : creation and iteration using Iterator

package CollectionFramework;

import java.util.*;

public class ExTreeHashmap1 {

public static void main(String[] args) {
Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");
Iterator iterator=colldemoMap.keySet().iterator();
while(iterator.hasNext()){
String key=iterator.next().toString();
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

2- Treemap : creation and iteration using ForEach

package CollectionFramework;

import java.util.*;

public class ExTreeHashmap2 {

public static void main(String[] args) {

Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");

for(Object key : colldemoMap.keySet()){
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

1- Sorting a collection

package CollectionFramework;

import java.util.*;
public class ExsortArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.sort(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

2- Searching in collection

package CollectionFramework;

import java.util.*;
public class ExsearchingArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);</pre>
<pre>Collections.sort(collDemo);
</pre>
<pre>int i = Collections.binarySearch(collDemo,12);

System.out.println("position of element is ");
System.out.println(i);
}
} 

3- Shuffling a collection

package CollectionFramework;

import java.util.*;
public class ExshuffleArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.shuffle(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

4– Reversing a collection

package CollectionFramework;

import java.util.*;
public class ExreverseArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.reverse(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

1- Treemap : creation and iteration using Iterator

package CollectionFramework;

import java.util.*;

public class ExTreeHashmap1 {

public static void main(String[] args) {
Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");
Iterator iterator=colldemoMap.keySet().iterator();
while(iterator.hasNext()){
String key=iterator.next().toString();
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

2- Treemap : creation and iteration using ForEach

package CollectionFramework;

import java.util.*;

public class ExTreeHashmap2 {

public static void main(String[] args) {

Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");

for(Object key : colldemoMap.keySet()){
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

1- Sorting a collection

package CollectionFramework;

import java.util.*;
public class ExsortArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.sort(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

2- Searching in collection

package CollectionFramework;

import java.util.*;
public class ExsearchingArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);</pre>
<pre>Collections.sort(collDemo);
</pre>
<pre>int i = Collections.binarySearch(collDemo,12);

System.out.println("position of element is ");
System.out.println(i);
}
} 

3- Shuffling a collection

package CollectionFramework;

import java.util.*;
public class ExshuffleArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.shuffle(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

4– Reversing a collection

package CollectionFramework;

import java.util.*;
public class ExreverseArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.reverse(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}
1- Treemap : creation and iteration using Iterator
package CollectionFramework;


import java.util.*;

public class ExTreeHashmap1 {

public static void main(String[] args) {
Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");
Iterator iterator=colldemoMap.keySet().iterator();
while(iterator.hasNext()){
String key=iterator.next().toString();
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

2- Treemap : creation and iteration using ForEach

package CollectionFramework;

import java.util.*;

public class ExTreeHashmap2 {

public static void main(String[] args) {

Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");

for(Object key : colldemoMap.keySet()){
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

1- Sorting a collection

package CollectionFramework;

import java.util.*;
public class ExsortArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.sort(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

2- Searching in collection

package CollectionFramework;

import java.util.*;
public class ExsearchingArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);
<pre>Collections.sort(collDemo);
</pre>
<pre>int i = Collections.binarySearch(collDemo,12);

System.out.println("position of element is ");
System.out.println(i);
}
} 

3- Shuffling a collection

package CollectionFramework;

import java.util.*;
public class ExshuffleArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.shuffle(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

4– Reversing a collection

package CollectionFramework;

import java.util.*;
public class ExreverseArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.reverse(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}
1- Treemap : creation and iteration using Iterator
package CollectionFramework;


import java.util.*;

public class ExTreeHashmap1 {

public static void main(String[] args) {
Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");
Iterator iterator=colldemoMap.keySet().iterator();
while(iterator.hasNext()){
String key=iterator.next().toString();
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 
2- Treemap : creation and iteration using ForEach
package CollectionFramework;


import java.util.*;

public class ExTreeHashmap2 {

public static void main(String[] args) {

Map colldemoMap=new TreeMap();
colldemoMap.put("Key1","Value1");
colldemoMap.put("key2","Value2");
colldemoMap.put("key3","Value3");

for(Object key : colldemoMap.keySet()){
String value=colldemoMap.get(key);
System.out.println(key);
System.out.println(value);
}
}
} 

1- Sorting a collection

package CollectionFramework;

import java.util.*;
public class ExsortArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.sort(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

2- Searching in collection

package CollectionFramework;

import java.util.*;
public class ExsearchingArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);
<pre>Collections.sort(collDemo);
</pre>
<pre>int i = Collections.binarySearch(collDemo,12);

System.out.println("position of element is ");
System.out.println(i);
}
} 

3- Shuffling a collection

package CollectionFramework;

import java.util.*;
public class ExshuffleArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.shuffle(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

4– Reversing a collection

package CollectionFramework;

import java.util.*;
public class ExreverseArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.reverse(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}
1- Sorting a collection

package CollectionFramework;


import java.util.*;
public class ExsortArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.sort(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

2- Searching in collection

package CollectionFramework;

import java.util.*;
public class ExsearchingArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);
<pre>Collections.sort(collDemo);
</pre>
<pre>int i = Collections.binarySearch(collDemo,12);


System.out.println("position of element is ");
System.out.println(i);
}
} 

3- Shuffling a collection

package CollectionFramework;

import java.util.*;
public class ExshuffleArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.shuffle(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

4– Reversing a collection

package CollectionFramework;

import java.util.*;
public class ExreverseArrList1 {

public static void main(String[] args) {
List collDemo=new ArrayList();

collDemo.add(5);
collDemo.add(15);
collDemo.add(15);
collDemo.add(12);

Collections.reverse(collDemo);

Iterator iterator=collDemo.iterator();
while(iterator.hasNext()){
System.out.println("using iterator :only next: "+iterator.next());
}
}
}

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.