This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Using maps Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Using maps " Watch "Using maps " New topic
Author

Using maps

james loveday
Greenhorn

Joined: Mar 06, 2009
Posts: 1
Hi all,

I'm hoping that somebody could look at this code and perhaps give me some pointers or something to think about to improve the efficiency. Ok so I have a map that holds strings and student class objects, from that I get the name of the student and using the score variable test that against the range of conditions, increasing the grade int accordingly then printing out the grade and the integer grade total. Like I said this works well enough but does anybody have any pointers that they could give me to think about to improve the efficiency. Please no Iterators I don't want to use one.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37950
    
  22
Welcome to JavaRanch

As you say, it works, and it looks nice code.

I presume you are using the Map elsewhere with get(name) and put(name, Student)?

Can you use the values() method of your Map to get a Collection<Student> and iterate through that with the for-each loop? It will probably only improve prformance slightly because hashing and finding values from a Map is usually a fast operation.

You are in fact using an Iterator; there is an Iterator which hides behind the for-each loop.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using maps
 
Similar Threads
using instance variables to sort "objects"
How can I add error handling facilities to this code?
accepting user input into into an array
concurrency error
Confused with file read