how do you store phone numbers using java collections

Answers were Sorted based on User's Feedback



how do you store phone numbers using java collections..

Answer / ankur dhoot

Shahnawaz Sheikh---sorry to say but don't you think that ur
ans is having some flaw...u r correct that phone no can be
store in HasMap but u have taken name as key but name can be
repeated while ph no is unique so don't u think that phone
no should be key in upper hash map.

Is This Answer Correct ?    9 Yes 2 No

how do you store phone numbers using java collections..

Answer / shahnawaz sheikh

Using HashMap.. can be one of the way.

HashMap hs = new HashMap();

hs.put("amit","989213232");
hs.put("john","989211422");
hs.put("Alex","989214578");

Is This Answer Correct ?    6 Yes 4 No

how do you store phone numbers using java collections..

Answer / saikatk

Sorry,sunny i am not agree with your scenario that one
number is common for husband & wife or between friends
etc.It is not real life scenario, phone no. are always
register with single person name ,that might be possible two
or many persons have
name,if we use HashMap , the Key might be different than
name like empid or securityid or some unique parameter.
Thanks

Is This Answer Correct ?    5 Yes 3 No

how do you store phone numbers using java collections..

Answer / rajeev

Hash map is only the answer to solve this type of problem....
HashMap hs=new HashMap();
hs.lateral={"Ankit Arora","9897655434"};


like this we can store the number using hash map table.

Is This Answer Correct ?    0 Yes 4 No

how do you store phone numbers using java collections..

Answer / sunny

We will have to assume that the names are going to be
unique. We may have a situation, that one number is common
for husband & wife or between friends etc. I mean, there is
a possibility, right? And normally you get the name of the
person and you have to find the phone number (I dont think
its going to be the other way round...in normal cases).
Then we need to have the name as the "Key", rather than
as "Value". Let me know, your thoughts on the same. Thanks.

Is This Answer Correct ?    0 Yes 5 No

Post New Answer

More Core Java Interview Questions

Does java return by reference?

0 Answers  


for what purpose we use applets ?

3 Answers   Mindlogicx,


can any body tell me? does advance java and j2ee both are same.

4 Answers   CTS, Infosys,


What is final, finally, finalize?

0 Answers  


How do you check if an arraylist is not empty?

0 Answers  






What is the point of java?

0 Answers  


What is string in java is it a data type?

0 Answers  


EDS (Electronic Data Systems India Pvt Ltd) at Chennai on 16-12-2006.

1 Answers   EDS,


Write POJO class as a key to hashmap???

2 Answers  


What is class??

0 Answers   Tech Mahindra,


Which class is the immediate superclass of the Container class?

1 Answers  


How can we create an immutable class in java?

0 Answers  


Categories