Java Generic Example – Parameterizd Type Eexample

Hello Freinds

Here I will try to write small program which will enables you to view why generics are there in java.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package genericbasic;

/**
 *
 * @author Vishal
 * In this example, I will show why generic are there
 * first we write tree separate overloaded method to print
 * reference type array.
 * after that we write single generic method which can
 * perform same tast.
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        // TODO code application logic here

        Integer[] intarray = {1,2,3,4,5};
        Double[] dblarray = {1.1,1.2,1.3,1.4};
        Character[] charray = {‘a’,’b’,’c’};

        System.out.println( “Array integerArray contains:” );
            printArray( intarray ); // pass an Integer array
        System.out.println( “\nArray doubleArray contains:” );
            printArray( dblarray ); // pass a Double array
        System.out.println( “\nArray characterArray contains:” );
              printArray( charray ); // pass a Character array

        Integer[] intarraygeneric = {1,2,3,4,5};
        Double[] dblarraygeneric = {1.1,1.2,1.3,1.4};
        Character[] charraygeneric = {‘a’,’b’,’c’};

              System.out.println( “Array integerArraygeneric contains:” );
              // How Calling Works
              /*
               *When the compiler encounters line  printArrayGeneric( intarraygeneric );
               , it first determines argument
               intarraygeneric’s type (i.e., Integer[]) and attempts to locate a
               named printArrayGeneric that specifies a single Integer[] parameter.
               There is no such method in this example. Next, the compiler
               determines whether there is a generic method named printArrayGeneric
               that specifies a single array parameter and uses a type parameter
               to represent the array element type. The compiler determines that
               method printArrayGeneric is a match and sets up a call to
               the method. The same process is repeated for the calls to method
               printArrayGeneric for double and character
               */
              
           // pass an Integer array
               printArrayGeneric( intarraygeneric );
        System.out.println( “\nArray doubleArraygeneric contains:” );
            printArrayGeneric( dblarraygeneric ); // pass a Double array
        System.out.println( “\nArray characterArraygeneric contains:” );
              printArrayGeneric( charraygeneric ); // pass a Character array
   
    }
    //Overloaded methods (printarray) are often used to perform similar
    //operations on different types of data.

    // method printArray to print Integer array
     public static void printArray( Integer[] inputArray )
       {
         // display array elements
          for ( Integer element : inputArray )
             System.out.printf( “%s “, element );

          System.out.println();
       } // end method printArray

     //Overloaded methods (printarray) are often used to perform similar
    //operations on different types of data.

// method printArray to print Double array
        public static void printArray( Double[] dblArray )
       {
         // display array elements
          for ( Double element : dblArray )
             System.out.printf( “%s “, element );

          System.out.println();
       } // end method printArray

    //Overloaded methods (printarray) are often used to perform similar
    //operations on different types of data.

// method printArray to print Character array
   public static void printArray( Character[] chArray )
       {
         // display array elements
          for ( Character element : chArray )
             System.out.printf( “%s “, element );

          System.out.println();
       } // end method printArray

   //Generic method

  // Compile will translate following method in below manner
   /*
    * check input type..its now Object – the root class
    1   public static void printArray( Object[] inputArray )
    2   {   
    3    
    4      for ( Object element : inputArray )   
    5      System.out.printf( “%s “, element );    
    6      System.out.println();   
    7   }
    */
   public static < E > void printArrayGeneric( E[] inputArray )
   {
       for ( E element : inputArray )
            System.out.printf( “%s “, element );
       System.out.println();
   } // end method printArray
}

most of the things are self explanatory, please copy and run the program to see output.

Java – J2EE Collection

How to run:

copy whole code and save file as main.java

If you are using Textpad then press ctrl+1 for compilation and ctrl+2 for run.
start coping from below line

import java.util.ArrayList;

import java. util.LinkedList;

import java.util.Iterator;

import java.util.Collection;

import java.util.Collections;

import java.util.HashMap;

import java.util.HashSet;

import java.util.Hashtable;

import java.util.LinkedHashMap;

import java.util.LinkedHashSet;

import java.util.List;

import java.util.ListIterator;

import java.util.PriorityQueue;

import java.util.Queue;

import java.util.TreeMap;

import java.util.TreeSet;

import java.util.Vector;

/**

 *

 * @author Vishal_Shah02

 */

public class Main {

    /**

     * @param args the command line arguments

     */

    public static void main(String[] args) {

        // TODO code application logic here

        System.out.println();

        System.out.println(“**********************************************************************”);

        System.out.println(” Array Example”);

        System.out.println(“**********************************************************************”);

        System.out.println();

        //ArrayList Example: Start

        ArrayList exarray = new ArrayList();

        //Add element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“add operation”);

        System.out.println(“——————————“);

        exarray.add(“Item1”);

        exarray.add(“Item2”);

        exarray.add(“Item3”);

        exarray.add(“Item4”);

        exarray.add(“Item5”);

        System.out.println(“Result:->”+ exarray);

        //iterate element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Iterating”);

        System.out.println(“——————————“);

        Iterator itarraylist = exarray.iterator();

        while(itarraylist.hasNext())

        {

            System.out.println(itarraylist.next());

        }

        //remove element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Removing”);

        System.out.println(“——————————“);

        exarray.remove(1);

        System.out.println(“Result:->”+ exarray);

         //copy element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“copy”);

        System.out.println(“——————————“);

         Object[] objarraylist = exarray.toArray();

         for(int i=0; i<objarraylist.length; i++)

         {

            System.out.println(objarraylist[i]);

         }

        // search element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Search”);

        System.out.println(“——————————“);

            if(exarray.contains(“Item1”))

            {

                System.out.println(“Match Found”);

            }

            else

            {

                System.out.println(“Match Not Found”);

            }

        // sort element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Sort”);

        System.out.println(“——————————“);

         Collections.sort(exarray);

         System.out.println(“Result:->”+ exarray);

        // replace element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“replace”);

        System.out.println(“——————————“);

        exarray.set(1, “Repplaced item”);

         System.out.println(“Result:->”+ exarray);

        // sub element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“sublist”);

        System.out.println(“——————————“);

        List sublist = exarray.subList(1, 4);

        System.out.println(sublist);

        // List iterator element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“List iterator”);

        System.out.println(“——————————“);

        ListIterator listitrarray = exarray.listIterator();

        listitrarray.next();

        listitrarray.add(“adding item via list iterator”);

         System.out.println(exarray);

         System.out.println(“Previous Index is : ” + listitrarray.previousIndex());

         System.out.println(“Next Index is : ” + listitrarray.nextIndex());

          while(listitrarray.hasPrevious())

              System.out.println(listitrarray.previous());

        //ArrayList Example: End

   // ***********************************************************************//

         //LinkedList Example: Start

        System.out.println();

        System.out.println(“**********************************************************************”);

        System.out.println(“LinkedList Example”);

        System.out.println(“**********************************************************************”);

        System.out.println();

        LinkedList exlinkedlist = new LinkedList();

        //Add element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“add operation”);

        System.out.println(“——————————“);

        exlinkedlist.add(“LinkedListItem1”);

        exlinkedlist.add(“LinkedListItem2”);

        exlinkedlist.add(“LinkedListItem3”);

        exlinkedlist.add(“LinkedListItem4”);

        exlinkedlist.add(“LinkedListItem5”);

        System.out.println(“Result:->”+ exlinkedlist);

        //iterate element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Iterating”);

        System.out.println(“——————————“);

        Iterator itLinkedlist = exlinkedlist.iterator();

        while(itLinkedlist.hasNext())

        {

            System.out.println(itLinkedlist.next());

        }

        //remove element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Removing”);

        System.out.println(“——————————“);

        exlinkedlist.remove(3);

        System.out.println(“Result:->”+ exlinkedlist);

         //copy element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“copy”);

        System.out.println(“——————————“);

        exlinkedlist.set(2,”Copied Item”);

         System.out.println(“Result:->”+ exlinkedlist);

        // search element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Search”);

        System.out.println(“——————————“);

         if(exlinkedlist.indexOf(“iterm1”)!= 1)

         {

             System.out.println(“Record Found”);

         }

         else

         {

             System.out.println(“Record not Found”);

         }

        // sort element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Sort”);

        System.out.println(“——————————“);

        Collections.sort(exlinkedlist);

        System.out.println(“Result:->”+ exlinkedlist);

        // replace element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“replace”);

        System.out.println(“——————————“);

        exlinkedlist.set(1,”Replaced LinkItem”);

         System.out.println(“Result:->”+ exlinkedlist);

        // sub element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“sublist”);

        System.out.println(“——————————“);

        List subLinkedList = exlinkedlist.subList(0, 2);

        System.out.println(“Result:->”+ subLinkedList);

        // get element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“get element”);

        System.out.println(“——————————“);

        if(exlinkedlist.contains(“Iterm 1”)  )

        {

            System.out.println(“element found”);

        }

        else

        {

            System.out.println(“element not found”);

        }

        //LinkedList Example: End

       //*******************************************************************//

    //Vector Example: Start

        System.out.println();

        System.out.println(“**********************************************************************”);

        System.out.println(“Vector Example”);

        System.out.println(“**********************************************************************”);

        System.out.println();

        Vector exvector = new Vector();

        //Add element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“add operation”);

        System.out.println(“——————————“);

        exvector.add(“Item1”);

        exvector.add(“Item2”);

        exvector.add(“Item3”);

        exvector.add(“Item4”);

        exvector.add(“Item5”);

        System.out.println(“Vector Result:->”+ exvector);

        //iterate element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Iterating”);

        System.out.println(“——————————“);

        Iterator itVector = exvector.iterator();

        while(itVector.hasNext())

        {

            System.out.println(itVector.next());

        }

        //remove element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Removing”);

        System.out.println(“——————————“);

        exvector.remove(1);

        System.out.println(“Result:->”+ exvector);

         //copy element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“copy”);

        System.out.println(“——————————“);

         Object[] objVector = exvector.toArray();

         for(int i=0; i<objVector.length; i++)

         {

            System.out.println(objVector[i]);

         }

        // search element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Search”);

        System.out.println(“——————————“);

            if(exvector.contains(“Item1”))

            {

                System.out.println(“Match Found”);

            }

            else

            {

                System.out.println(“Match Not Found”);

            }

        // sort element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Sort”);

        System.out.println(“——————————“);

         Collections.sort(exvector);

         System.out.println(“Result:->”+ exvector);

        // replace element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“replace”);

        System.out.println(“——————————“);

        exvector.set(1, “Repplaced item”);

         System.out.println(“Result:->”+ exvector);

        // sub element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“sublist”);

        System.out.println(“——————————“);

        List sublistvector = exvector.subList(1, 4);

        System.out.println(sublistvector);

        // List iterator element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“List iterator”);

        System.out.println(“——————————“);

        ListIterator listitrarrayvector = exvector.listIterator();

        listitrarrayvector.next();

        listitrarrayvector.add(“adding item via list iterator”);

         System.out.println(exvector);

         System.out.println(“Previous Index is : ” + listitrarrayvector.previousIndex());

         System.out.println(“Next Index is : ” + listitrarrayvector.nextIndex());

          while(listitrarray.hasPrevious())

              System.out.println(listitrarray.previous());

        //Vector Example: End

        System.out.println();

        System.out.println(“**********************************************************************”);

        System.out.println(” HashSet Example”);

        System.out.println(“**********************************************************************”);

        System.out.println();

        //HashSet Example: Start

        HashSet exHashSet = new HashSet();

        //Add element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“add operation”);

        System.out.println(“——————————“);

        exHashSet.add(“HashSetItem1”);

        exHashSet.add(“HashSetItem2”);

        exHashSet.add(“HashSetItem3”);

        exHashSet.add(“HashSetItem5”);

        exHashSet.add(“HashSetItem6”);

        System.out.println(“Result:->”+ exHashSet);

        //iterate element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Iterating”);

        System.out.println(“——————————“);

        Iterator itHashSet = exHashSet.iterator();

        while(itHashSet.hasNext())

        {

            System.out.println(itHashSet.next());

        }

        //remove element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Removing”);

        System.out.println(“——————————“);

        if(exHashSet.remove(“HashSetItem1”)            )

        {

                System.out.println(“item removed”);

        }

        else

        {

                System.out.println(“item not removed”);

        }

        System.out.println(“Result:->”+ exHashSet);

         //copy element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“copy”);

        System.out.println(“——————————“);

        Object[] objhashset = exHashSet.toArray();

        for(int index=0; index < objhashset.length ; index++)

            System.out.println(objhashset[index]);

        // search element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Search”);

        System.out.println(“——————————“);

        if(exHashSet.contains(“HashSetItem2”))

        {

         System.out.println(“item found”);

        }

         else

        {

         System.out.println(“item does not found”);

        }

        // sub element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Cloning”);

        System.out.println(“——————————“);

        Object copyhashset = exHashSet.clone();

        System.out.println(copyhashset);

        //HashSet Example: End

    //*******************************************************************//

        System.out.println();

        System.out.println(“**********************************************************************”);

        System.out.println(“TreeSet Example”);

        System.out.println(“**********************************************************************”);

        System.out.println();        //TreeSet Example: Start

        TreeSet exTreeSet = new TreeSet();

        //Add element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“add operation”);

        System.out.println(“——————————“);

        exTreeSet.add(“TreeSetItem1”);

        exTreeSet.add(“TreeSetItem2”);

        exTreeSet.add(“TreeSetItem3”);

        exTreeSet.add(“TreeSetItem5”);

        exTreeSet.add(“TreeSetItem6”);

        System.out.println(“Result:->”+ exTreeSet);

        //iterate element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Iterating”);

        System.out.println(“——————————“);

        Iterator itTreeSet = exTreeSet.iterator();

        while(itTreeSet.hasNext())

        {

            System.out.println(itTreeSet.next());

        }

        //remove element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Removing”);

        System.out.println(“——————————“);

        if(exTreeSet.remove(“TreeSetItem1”)            )

        {

                System.out.println(“item removed”);

        }

        else

        {

                System.out.println(“item not removed”);

        }

        System.out.println(“Result:->”+ exTreeSet);

         //copy element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“copy”);

        System.out.println(“——————————“);

        Object[] objTreeSet = exTreeSet.toArray();

        for(int index=0; index < objTreeSet.length ; index++)

            System.out.println(objTreeSet[index]);

        // search element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Search”);

        System.out.println(“——————————“);

        if(exTreeSet.contains(“TreeSetItem2”))

        {

         System.out.println(“item found”);

        }

         else

        {

         System.out.println(“item does not found”);

        }

        // sub element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Cloning”);

        System.out.println(“——————————“);

        Object copyTreeSet = exTreeSet.clone();

        System.out.println(copyTreeSet);

        //TreeSet Example: End

       //*******************************************************************//

         System.out.println();

        System.out.println(“**********************************************************************”);

        System.out.println(” LinkedHashSet Example”);

        System.out.println(“**********************************************************************”);

        System.out.println();

        //LinkedHashSet Example: Start

        LinkedHashSet exLinkedHashSet = new LinkedHashSet();

        //Add element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“add operation”);

        System.out.println(“——————————“);

        exLinkedHashSet.add(“LinkedHashSetItem1”);

        exLinkedHashSet.add(“LinkedHashSetItem2”);

        exLinkedHashSet.add(“LinkedHashSetItem3”);

        exLinkedHashSet.add(“LinkedHashSetItem5”);

        exLinkedHashSet.add(“LinkedHashSetItem6”);

        System.out.println(“Result:->”+ exLinkedHashSet);

        //iterate element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Iterating”);

        System.out.println(“——————————“);

        Iterator itLinkedHashSet = exLinkedHashSet.iterator();

        while(itLinkedHashSet.hasNext())

        {

            System.out.println(itLinkedHashSet.next());

        }

        //remove element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Removing”);

        System.out.println(“——————————“);

        if(exLinkedHashSet.remove(“LinkedHashSetItem1”)            )

        {

                System.out.println(“item removed”);

        }

        else

        {

                System.out.println(“item not removed”);

        }

        System.out.println(“Result:->”+ exLinkedHashSet);

         //copy element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“copy”);

        System.out.println(“——————————“);

        Object[] objLinkedHashSet = exLinkedHashSet.toArray();

        for(int index=0; index < objLinkedHashSet.length ; index++)

            System.out.println(objLinkedHashSet[index]);

        // search element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Search”);

        System.out.println(“——————————“);

        if(exLinkedHashSet.contains(“LinkedHashSetItem2”))

        {

         System.out.println(“item found”);

        }

         else

        {

         System.out.println(“item does not found”);

        }

        // sub element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Cloning”);

        System.out.println(“——————————“);

        Object copyLinkedHashSet = exLinkedHashSet.clone();

        System.out.println(copyLinkedHashSet);

        //LinkedHashSet Example: End

       //*******************************************************************//

         System.out.println();

        System.out.println(“**********************************************************************”);

        System.out.println(” HashMap Example”);

        System.out.println(“**********************************************************************”);

        System.out.println();      //HashMap Example: Start

        HashMap exHashMap = new HashMap();

        //Add element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“add operation”);

        System.out.println(“——————————“);

        exHashMap.put(“key1″,”HashMapItem1”);

        exHashMap.put(“key2″,”HashMapItem2”);

        exHashMap.put(“key3″,”HashMapItem3”);

        exHashMap.put(“key4″,”HashMapItem5”);

        exHashMap.put(“key5″,”HashMapItem6”);

        System.out.println(“Result:->”+ exHashMap);

        //retrive element

            //retrieve value using Object get(Object key) method of Java HashMap class

        Object obj = exHashMap.get(“HashMapItem6”);

        System.out.println(“Retrival:->”+obj);

        //remove element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Removing”);

        System.out.println(“——————————“);

        exHashMap.remove(“key4”);

        System.out.println(“Result:->”+ exHashMap);

         //Iterate element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Iterate-values”);

        System.out.println(“——————————“);

        Collection clnhashvalue = exHashMap.values();

        Iterator itrhashmap = clnhashvalue.iterator();

        while(itrhashmap.hasNext())

        {

            System.out.println(itrhashmap.next());

        }

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Iterate-keys”);

        System.out.println(“——————————“);

        Collection clnhashkey = exHashMap.keySet();

        Iterator itrhashmapkey = clnhashkey.iterator();

        while(itrhashmapkey.hasNext())

        {

            System.out.println(itrhashmapkey.next());

        }

        // search element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Search-Value”);

        System.out.println(“——————————“);

        if(exHashMap.containsValue(“HashMapItem1”))

        {

            System.out.println(“Hashmap Value found”);

        }

        else

        {

            System.out.println(“Hashmap Value Not found”);

        }

         System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Search-Key”);

        System.out.println(“——————————“);

        if(exHashMap.containsKey(“key3”))

        {

            System.out.println(“Hashmap Key found”);

        }

        else

        {

            System.out.println(“Hashmap Key Not found”);

        }

        // sub element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Cloning”);

        System.out.println(“——————————“);

        Object copyHashMap = exHashMap.clone();

        System.out.println(copyHashMap);

        //HashMap Example: End

          //*******************************************************************//

        System.out.println();

        System.out.println(“**********************************************************************”);

        System.out.println(” LinkedHashMap Example”);

        System.out.println(“**********************************************************************”);

        System.out.println();

        //LinkedHashMap Example: Start

        LinkedHashMap exLinkedHashMap = new LinkedHashMap();

        //Add element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“add operation”);

        System.out.println(“——————————“);

        exLinkedHashMap.put(“key1″,”LinkedHashMapItem1”);

        exLinkedHashMap.put(“key2″,”LinkedHashMapItem2”);

        exLinkedHashMap.put(“key3″,”LinkedHashMapItem3”);

        exLinkedHashMap.put(“key4″,”LinkedHashMapItem5”);

        exLinkedHashMap.put(“key5″,”LinkedHashMapItem6”);

        System.out.println(“Result:->”+ exLinkedHashMap);

        //retrive element

            //retrieve value using Object get(Object key) method of Java LinkedHashMap class

        Object objLinkedHashmap = exLinkedHashMap.get(“LinkedHashMapItem6”);

        System.out.println(“Retrival:->”+objLinkedHashmap);

        //remove element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Removing”);

        System.out.println(“——————————“);

        exLinkedHashMap.remove(“key4”);

        System.out.println(“Result:->”+ exLinkedHashMap);

         //Iterate element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Iterate-values”);

        System.out.println(“——————————“);

        Collection clnlinkhashvalue = exLinkedHashMap.values();

        Iterator itrLinkedHashMap = clnlinkhashvalue.iterator();

        while(itrLinkedHashMap.hasNext())

        {

            System.out.println(itrLinkedHashMap.next());

        }

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Iterate-keys”);

        System.out.println(“——————————“);

        Collection clnlinkhashkey = exLinkedHashMap.keySet();

        Iterator itrLinkedHashMapkey = clnlinkhashkey.iterator();

        while(itrLinkedHashMapkey.hasNext())

        {

            System.out.println(itrLinkedHashMapkey.next());

        }

        // search element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Search-Value”);

        System.out.println(“——————————“);

        if(exLinkedHashMap.containsValue(“LinkedHashMapItem1”))

        {

            System.out.println(“LinkedHashMap Value found”);

        }

        else

        {

            System.out.println(“LinkedHashMap Value Not found”);

        }

         System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Search-Key”);

        System.out.println(“——————————“);

        if(exLinkedHashMap.containsKey(“key3”))

        {

            System.out.println(“LinkedHashMap Key found”);

        }

        else

        {

            System.out.println(“LinkedHashMap Key Not found”);

        }

        // sub element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Cloning”);

        System.out.println(“——————————“);

        Object copyLinkedHashMap = exLinkedHashMap.clone();

        System.out.println(copyLinkedHashMap);

        //LinkedHashMap Example: End

          //*******************************************************************//

   System.out.println();

        System.out.println(“**********************************************************************”);

        System.out.println(” HashTable Example”);

        System.out.println(“**********************************************************************”);

        System.out.println();

             //HashTable Example: Start

        Hashtable exHashTable = new Hashtable();

        //Add element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“add operation”);

        System.out.println(“——————————“);

        exHashTable.put(“key1″,”HashTableItem1”);

        exHashTable.put(“key2″,”HashTableItem2”);

        exHashTable.put(“key3″,”HashTableItem3”);

        exHashTable.put(“key4″,”HashTableItem5”);

        exHashTable.put(“key5″,”HashTableItem6”);

        System.out.println(“Result:->”+ exHashTable);

        //retrive element

            //retrieve value using Object get(Object key) method of Java HashTable class

        Object objHashTable = exHashTable.get(“HashTableItem6”);

        System.out.println(“Retrival:->”+objHashTable);

        //remove element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Removing”);

        System.out.println(“——————————“);

        exHashTable.remove(“key4”);

        System.out.println(“Result:->”+ exHashTable);

         //Iterate element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Iterate-values”);

        System.out.println(“——————————“);

        Collection clnhashtablevalue = exHashTable.values();

        Iterator itrHashTable = clnhashtablevalue.iterator();

        while(itrHashTable.hasNext())

        {

            System.out.println(itrHashTable.next());

        }

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Iterate-keys”);

        System.out.println(“——————————“);

        Collection clnhashtablekey = exHashTable.keySet();

        Iterator itrHashTablekey = clnhashtablekey.iterator();

        while(itrHashTablekey.hasNext())

        {

            System.out.println(itrHashTablekey.next());

        }

        // search element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Search-Value”);

        System.out.println(“——————————“);

        if(exHashTable.containsValue(“HashTableItem1”))

        {

            System.out.println(“HashTable Value found”);

        }

        else

        {

            System.out.println(“HashTable Value Not found”);

        }

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Search-Key”);

        System.out.println(“——————————“);

        if(exHashTable.containsKey(“key3”))

        {

            System.out.println(“HashTable Key found”);

        }

        else

        {

            System.out.println(“HashTable Key Not found”);

        }

        // sub element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Cloning”);

        System.out.println(“——————————“);

        Object copyHashTable = exHashTable.clone();

        System.out.println(copyHashTable);

        //HashTable Example: End

          //*******************************************************************//

        System.out.println();

        System.out.println(“**********************************************************************”);

        System.out.println(” TreeMap Example”);

        System.out.println(“**********************************************************************”);

        System.out.println();

            //Treemap Example: Start

        TreeMap exTreemap = new TreeMap();

        //Add element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“add operation”);

        System.out.println(“——————————“);

        exTreemap.put(“key1″,”TreemapItem1”);

        exTreemap.put(“key2″,”TreemapItem2”);

        exTreemap.put(“key3″,”TreemapItem3”);

        exTreemap.put(“key4″,”TreemapItem5”);

        exTreemap.put(“key5″,”TreemapItem6”);

        System.out.println(“Result:->”+ exTreemap);

        //retrive element

            //retrieve value using Object get(Object key) method of Java Treemap class

        Object objTreemap = exTreemap.get(“TreemapItem6”);

        System.out.println(“Retrival:->”+objTreemap);

        //remove element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Removing”);

        System.out.println(“——————————“);

        exTreemap.remove(“key4”);

        System.out.println(“Result:->”+ exTreemap);

         //Iterate element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Iterate-values”);

        System.out.println(“——————————“);

        Collection clntreemapvalue = exTreemap.values();

        Iterator itrTreemap = clntreemapvalue.iterator();

        while(itrTreemap.hasNext())

        {

            System.out.println(itrTreemap.next());

        }

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Iterate-keys”);

        System.out.println(“——————————“);

        Collection clntreemapkey = exTreemap.keySet();

        Iterator itrTreemapkey = clntreemapkey.iterator();

        while(itrTreemapkey.hasNext())

        {

            System.out.println(itrTreemapkey.next());

        }

        // search element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Search-Value”);

        System.out.println(“——————————“);

        if(exTreemap.containsValue(“TreemapItem1”))

        {

            System.out.println(“Treemap Value found”);

        }

        else

        {

            System.out.println(“Treemap Value Not found”);

        }

         System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Search-Key”);

        System.out.println(“——————————“);

        if(exTreemap.containsKey(“key3”))

        {

            System.out.println(“Treemap Key found”);

        }

        else

        {

            System.out.println(“Treemap Key Not found”);

        }

        // sub element

        System.out.println(“”);

        System.out.println(“——————————“);

        System.out.println(“Cloning”);

        System.out.println(“——————————“);

        Object copyTreemap = exTreemap.clone();

        System.out.println(copyTreemap);

        //Treemap Example: End

        System.out.println();

        System.out.println(“**********************************************************************”);

        System.out.println(” Queue Example”);

        System.out.println(“**********************************************************************”);

        System.out.println();

        //Queue Example: Start

        Queue<String> exqueue = new LinkedList<String>();

        exqueue.add(“Shah”);

        exqueue.add(“Vishal”);

        exqueue.add(“Infy”);

        Iterator it = exqueue.iterator();

        while(it.hasNext())

        {

            System.out.println(it.next());

        }

        System.out.println(“Peek Example/ null and no exception:->”+ exqueue.peek());

        System.out.println(exqueue);

        System.out.println(“Poll Example/ remove first element:->”+ exqueue.poll());

        System.out.println(exqueue);

        System.out.println(“Element Example/ throw exception:->”+ exqueue.element());

        int[] iarray = {1,2,3,4,5,6};

        PriorityQueue<Integer> pq1 = new PriorityQueue<Integer>();

        for(int x:iarray)

        {

            pq1.offer(x);

        }

        System.out.println(pq1);

        for(int x:iarray)

        {

            pq1.poll();

        }

        System.out.println(pq1);

        //Queye Example: end

    }

}

Ultimate Rapidshare Tutorial

Ultimate Rapidshare Tutorial

First of all, I’m surprised that not that many people know about easy tool for decoding the source code from the RapidShare html. Here is the best tool so far created, in my opinion Rapid DeCoder v0.1

direct download link:
http://gravityfx.org/dl/exe/RD.exe

Let’s make an easy example now!

1st. We need to find some RapidShare links, we will use Google and some simple commands: allinurl:rapidshare.de/files/

Here is the first hit, link:

http://rapidshare.de/files/1246427/Model.doc.html

2nd. Disable JavaScript in your firewall or browser and go to above link, then click Free (button).

3rd. Fire up the Rapid DeCoder and open the pages html source code you should see some thing like this:

unescape(‘%3C%68%32%3E%3C%66%6F%6E%74%20%63%6F%
6C%6F%72%3D%22%23%43%43%30%30%30%30%22%3E%20%44%
6F%77%6E%6C%6F%61%64%3A%3C%2F%66%6F%6E%74%3E%20%
3C%61%20%68%72%65%66%3D%22%68%74%74%70%3A%2F%2F%
64%6C%32%2E%72%61%70%69%64%73%68%61%72%65%2E%64%
65%2F%66%69%6C%65%73%2F%31%32%34%36%34%32%37%2F%
32%30%34%34%37%36%32%39%2F%4D%6F%64%65%6C%2E%64%
6F%63%22%3E%4D%6F%64%65%6C%2E%64%6F%63%3C%2F%61%
3E%3C%2F%68%32%3E’)

Copy this source code starting with unescape( and ending with ), to Rapid DeCoder and click DeCode (button)

4th. You should see some thing like this:

unescape(‘<h2><font color=”#CC0000″> Download:</font>
<a href=”http://dl2.rapidshare.de/files/1246427/20447629/Model.doc”>Model.doc</a></h2>&#8217;)

Here is your decoded direct link, now just copy and paste the link to the browser and download without even waiting for the timer!

Result direct link:

http://dl2.rapidshare.de/files/1246427/20447629/Model.doc

Thanks

How to Get a New IP Address Even If You Have a Static IP

This is quite interesting, get it from a forum, and credits go to Mojojojojo. Just follow these simple steps below, to get a new IP address even you have a static/fixed IP!

This trick is very useful for those who cannot use this method because the have static IP address.

To start off, you need a direct connection to your modem and computer. If you have a router, disconnect it and directly hook up your modem to your computer.

1. Open up the command prompt by pressing Start->Run and typing in cmd

2. In the command prompt, type “Ipconfig/all”. This will tell you your current IP Address. After, type “ipconfig/release”. Keep the command prompt open for easy access.

3. Go to “Network Connections” (accessible through the control panel). Right click “Local Area Connection” and click “Properties”

4. With “Internet Protocol (TCP/IP) selected, click the “Properties” button.

5. A new window will open. Under the “General” tab, select “Use the Following IP address”. Under “Ip Address”, put “10.0.0.1″. Press the “Tab” key on your keyboard.

6. Press Ok on both open windows.

7. Repeat steps 3-4. Under the “General” tab, press the radio button “Automatically Assign Me an Ip Address”. Press ok on both windows.

8. Go back to the command prompt and type in “Ipconfig/all”. You’ll now notice you have a new IP address.

So, this will be handy if you want to by-pass Rapidshare 1 hour download limit, provided that you have a static IP address.

How to Access Restricted Websites Using Google

This is a little tutorial to show you how to use Google Translate to access blocked websites or restricted pages due to a proxy block (by your office, school, university, etc.)

We all know that Google is more than a search engine; we do use it as provider for email, mapping, news and many other services. But do you know, indirectly, Google is also a free proxy service.

Proxy is a device that stands between a PC and the internet, providing all the connections to the world wide web. What a proxy does is to receive all data from a requested site, so when you access web pages all data come from proxy.

What’s the purpose for Google as a proxy? We often use office/school/university connections, usually those services are set to provide more safety, blocking the access to undesidered web sites (the “black list”). What you can do now is use Google translator service (language tools) as a proxy to bypass the restrictions set for our connection!

You just need to type the following URL in the address bar:

http://www.google.com/translate?langpair=en|en&u=www.restricted.com

Note: http://www.restricted.com refers to the URL that you want to browse.

What you’ll get is the translation (English to English – that’s the content) of the page you want to see, your connection is directed to a Google.com page so this page won’t be blocked (would be blocked only with Google.com on the black list), no matter what’s the content.

how to hack password of yahoo hotmail gmail or irc…all

hi all in this tutorial i will show you how to hack passwords all passwords

this is the link:
*********************************************************************
http://www.MegaShare.com/41081
password to extract is :
by mr.rip