| |
GeekInterview.com > Placement Papers > Oracle > Java
| Print | |
Question: How can u implement hashmap if u r not having it in java?
|
| May 05, 2008 14:36:16 |
#1 |
| santoshbwn |
Member Since: May 2008 Total Comments: 2 |
RE: How can u implement hashmap if u r not having it in java? |
class container { //put the setters and getters of key and values object key=null; //acting as key List values=null; public void Container() { key=new Object(); values=new ArrayList(); }
public insert(object key,object values) { this.key=key; this.values=values; } }
class HashMapCustom { Container c=null; List recordList;
void HashMapX() { c=new Container(); recordList=new ArrayList(); }
void put(object keyP,Object values) { c.insert(keyP,values); recordList.add(c); }
void Object get(object keyP) { for(int i=0;i<recordList.size();i++) { object fetch=recordList.get(i); //Just check the follwoing code...i have not executed it...it's a validation check //Converting to string for equal checking..whether it be int,float,string or whatever if(keyP instance of fetch.class && keyP.toString().equals(fetch.toString())) { object ret=fetch.getValues(); break; } } return ret; } } |
| |
Back To Question | |