An open API service indexing awesome lists of open source software.

https://github.com/mukul273/java-collections

Java Collections for beginners
https://github.com/mukul273/java-collections

collections git github java

Last synced: about 2 months ago
JSON representation

Java Collections for beginners

Awesome Lists containing this project

README

          

This is for Basic understanding of Java Collections Framework.

/*
* Consider:
* 1. what you need the collection to do
* 2. are you using the fastest collection for your purposes
* (think about insertion/deletion, retrieval and traversal
*/

//////////////// LISTS ///////////////////////////////////

// Store lists of objects
// Duplicates are allowed
// Objects remain in order
// Elements are indexed via an integer
// cf. shopping list
// Checking for particular item in list is slow
// Looking an item up by index is fast
// Iterating through lists is relatively fast
// Note: you can sort lists if you want to.

// If you only add or remove items at end of list, use ArrayList.
List list1 = new ArrayList();

// Removing or adding items elsewhere in the list?
List list2 = new LinkedList();

////////////////SETS ///////////////////////////////////

// Only store unique values
// Great for removing duplicates
// Not indexed, unlike lists
// Very fast to check if a particular object exists
// If you want to use your own objects, you must implement hashCode() and equals().

// Order is unimportant and OK if it changes?
// HashSet is not ordered.
Set set1 = new HashSet();

// Sorted in natural order? Use TreeSet - must implement Comparable for custom types
// (1,2,3 ..., a,b,c.... etc)
Set set2 = new TreeSet();

// Elements remain in order they were added
Set set3 = new LinkedHashSet();

////////////////MAPS ///////////////////////////////////

// Key value pairs.
// Like lookup tables
// Retrieving a value by key is fast
// Iterating over map values is very slow
// Maps not really optimised for iteration
// If you want to use your own objects as keys, you must implement hashCode() and equals().

// Keys not in any particular order, and order liable to change.
Map map1 = new HashMap();

// Keys sorted in natural order - must implement Comparable for custom types
Map map2 = new TreeMap();

// Keys remain in order added
Map map3 = new LinkedHashMap();

// There are also the SortedSet and SortedMap interfaces.