How can u implement hashmap if u r not having it in java?

This question is related to Oracle Interview

Showing Answers 1 - 1 of 1 Answers

santoshbwn

  • May 10th, 2008
 

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;
}
}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions