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.
Snigdha<br />Sun Certified Programmer for the Java™ 2 Platform
Joined: Nov 07, 2000
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?
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.
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Joined: Jan 30, 2000
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.
Joined: Nov 07, 2000
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.
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.