File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Efficient Implmentaion of List and Map

 
Santhosh Kumar
Ranch Hand
Posts: 242
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
I would like to know the efficient implmentaion of List and Map for jdk 1.3.1.
Thanks,
Santhosh.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, usually I use ArrayList and HashMap. Sometimes LinkedList or TreeMap (depending on my needs). If you're curious you can find the source code for all these in src.jar. Is that what you meant?
 
Snigdha Solanki
Ranch Hand
Posts: 128
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The implementations of List in JDK1.3.1 are Vector,ArrayList,LinkedList and implementations of Map are HashMap, Hashtable, RenderingHints, WeakHashMap, Attributes. Except Vector and Hashtable rest all are unsynchronized and hence offer better performance.
 
Santhosh Kumar
Ranch Hand
Posts: 242
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Jim and Solanki for the reply.
I have read somewhere in the net that, if you implement the list and map yourself, it will offer better performance than ArrlyList or HashMap... so I was looking any info regd this? any URL where I can get this or any guidelines?
 
Bosun Bello
Ranch Hand
Posts: 1510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what you mean by implement it your self...write your own? In most cases, the performance gains from writing your own, if any, will not be a major factor. The current implementations of HashMap, ArrayList, etc. Should suffice.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that the idea of writing your own implementations comes from two things. One is that the initial implementations of come Collections weren't as good as they could be. But they've improved in subsequent releases. The other is that for collections of primitive values, it may be desirable to eliminate the overhead of creating object wrappers for each primitive. The latter also can apply to collections of specific Object subclasses - if you know that all theo objects in your List are really Strings, you can eliminate some casting by creating a list that only works with Strings, and stores them in a String[] array internally rather than an Object[] array. (Note that technically you're no longer implementing a Collection if it doesn't accept Objects.) There are probably some other situations where you might want to get specific performance characteristics which are different from the generic Collection implementations.
However, it is almost certainly a bad idea to try to do this unless and until you determine that the current performance is unacceptable, and that the bottleneck is in fact in an area which you can fix with a different implementation. Optimizing a collection is not as easy as it may seem, and the current Collection implementations are really pretty good. It will be very easy to create something slower that you'd get with these implementations, and even when you can improve on it, the difference will often be negligible.
 
Santhosh Kumar
Ranch Hand
Posts: 242
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After doing some benchmarking, here is what I have decided.
Use ArrayList and ArrayMap. Our requirement does not have much of deletions. So I think these two would be suffice. But I have given a wrapper for each type of object I want to keep. for ex., if want to keep list of users, I have made UserList which extends from ArrayList. So that in future if I want, make it as array users (User[]) to give better performance.
Thanks you very much for the input. If you think of anything fishy with this approach, pl reply.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Santhosh Kumar:
...But I have given a wrapper for each type of object I want to keep. for ex., if want to keep list of users, I have made UserList which extends from ArrayList. So that in future if I want, make it as array users (User[]) to give better performance.
Thanks you very much for the input. If you think of anything fishy with this approach, pl reply.

Indeed. By extending the class you are still exposing the original classes interface. Which means people can still insert ANY Object or retrieve an Object from the superclass interface.
Might be a better choice to simply aggregate the Object. Of course in this case you cant implement the Collection interface and use any of the helpers in the Collections class.

in this case nobody can call get directory on the superclass and retrieve and object or class Object, nor can they put an object of class Object.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic