File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Collections Queries in Java. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Collections Queries in Java." Watch "Collections Queries in Java." New topic
Author

Collections Queries in Java.

Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

I have below questions in Collections with respect to Java.

1> Suppose i have SSN(Social Security Number) as Key in Hashmap,The Value in HashMap being a combination of (customer name,customer address,customer pincode)

HashMap [key,Value]-->[SSN,(customer name,customer address,customer pincode)]

what datastructure i would use for the above implementation in Java and how would i retrieve customer details(name,address,pincode) based on SSN.Example for the above implementation provided will be helpful.


2> I have HashMap of [Key,Value] pair -> [bank account number,telephone no]

HashMap has got 3 entries
Ex:HashMap m = new HashMap();
m.put("12345","08026583026");
m.put("12346","08026583027");
m.put("12347","08026583028");

How do i retrieve telephone number based on bank account number,assume user inputs 12347 and the the result should be 08026583028 ??Example for the above implementation provided will be helpful.??



3> I have HashMap of [Key,Value] -> [telephone no,bank account number]

HashMap has got 3 entries
Ex:HashMap m = new HashMap();
m.put("08026583026","12345");
m.put("08026583027","12346");
m.put("08026583028","12347");
How do i retrieve bank account number based on telephone number,assume user inputs 08026583028 and the the result should be 12347 ??Example for the above implementation provided will be helpful.??

4> Give the Implementation /Algorithm to control 3 elevators in Core Java ??

Help provided will ne highly appreciated.

--
Deepak Lal


When The Going Gets Tougher,The Tougher gets Going
Angel Taveras
Ranch Hand

Joined: Nov 13, 2008
Posts: 84

Hello Deepak, the approach below can be used for 1,2,3.

You could create a class Customer that has a (name,address,pincode) properties in it, even the SSN. Then put the SSN as key in the map. Like this
Map.put(SSN,customerInstance).

regards,
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1295
For 1: Do you know how to create a simple class in Java with instance fields and accessor methods?

For 2-3: I would look to the API of java.util.HashMap. You should be able to find a method that takes a key as a parameter and returns the corresponding object that was stored in the Map.

For 4: You'll have to work that out on your own. We don't do other peoples homework around here.


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Hi Angel and Garett,
Can you give me a example on how to proceed for Question 1,2,3.
I'm finding it a bit difficult to implement.If you can provide me with the implementation for the same.it would be helpful.

Help provided will be highly appreciated.

--
Deepak Lal
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

Please Show Some Effort. Problems 2 and 3 are basically the same (how to get the value for a key) and Garrett has given you a hint to find the single method you need for this.

And I can't believe you don't know how to create the Customer class Angel has described. You've been on this board long enough to at least be able to create such a simple thing.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Collections Queries in Java.
 
Similar Threads
HashMap()
Collections - Search by value
Problems w/ a HashMap
Table Selection Lost
query disaster