I hope to be useful for everyone.
import java.util.ArrayList; import java.util.HashMap; import java.util.Hashtable; import java.util.List; import java.util.Map; //Note : Java can't insert primitives into Tables,Lists or anything else expecting an Object // So java provides wrapper types for this purpose (int ---> Integer). public class GenericDemo { /** Creates a new instance of GenericDemo */ public GenericDemo() { } public static void main(String args[]){ /* *Here i'm create a arraylist hold integers only *Simple if you want create generic type *write_Container_Name <TypeName> varName = new write_Container_Name <TypeName>(); *varName.Member Function and so on. */ List<Integer> iArrayList = new ArrayList<Integer>(); iArrayList.add(100); iArrayList.add(500); //View Container content. for(int i = 0 ; i < iArrayList.size();i++) { System.out.println(iArrayList.get(i)); } /* *Here i'm create a Maplist hold string for every item. */ Map<String,String> mplist = new HashMap<String,String>(); mplist.put("0","Author : Mohamed Saleh"); mplist.put("1","Subject : Demonstration about Generic Programming"); mplist.put("2","Audience : Every Programmer what to know how Generic Programming Looks Like."); mplist.put("3" , "Subject : Generic Programming\nThis is (Genetics):Using DataStructure Object Depend On my Own Like (Any Object)\n"); mplist.put("4","Sample without Generic : //Declare a ArrayList\n ArrayList al = new ArrayList();\n al.add(\"Object\");\n al.add(500);"); mplist.put("5","Hint 01//This ArrayList al will manipulate with any object Type\nWhat if i want to manipulate with strings Only for specific purpose.\nSo i have to declate special type ArrayList for string in Same Time."); mplist.put("6","Sample with Generic// ArrayList<String> myStrList = new ArrayList<String>()"); mplist.put("7","Hint 02//Then Using Current new Object Directly"); for(int x = 0 ; x < mplist.size() ; x++){ // Here i want to view data holds in MapList and there is a restriction (View By Key not Index Like Arrays or ArrayList) // so i did a convert or casting to content of Key to Object System.out.println(mplist.get((Object)Integer.toString(x))); } /* *Here i'm create a Hashtable holds doubles only */ Hashtable<Double,Double> dblTable = new Hashtable<Double,Double>(); } }