View RSS Feed

Java Collection

Java collection Best Practices?

Rate this Entry
by , 01-08-2012 at 12:22 PM (1945 Views)
Following are the best practices related to collection framework.

Use ArrayLists, HashMap when required to avoid thread synchronization overhead. Also you can use arrays when possible. You can achieve thread synchronization by:

Java Code: This is an example of list and map
Map myMap = Collections.synchronizedMap(myMap);
List myList = Collections.synchronizedList(myList);
Specify the initial values for ArrayList and HashMap because these grow periodically to get space for new elements.
Write your code using interfaces not implementation.
Do not store unrelated objects into a collection. Write wrapper classes for your collection classes. Also try to use composite design pattern.

Submit "Java collection Best Practices?" to Facebook Submit "Java collection Best Practices?" to Digg Submit "Java collection Best Practices?" to del.icio.us Submit "Java collection Best Practices?" to StumbleUpon Submit "Java collection Best Practices?" to Google

Updated 01-15-2012 at 09:35 AM by Java Collection

Categories
Tutorial

Comments