Java Collections - ashwin-shetty/Documents-Wiki GitHub Wiki
Types of List
Type |
Description |
Arraylist |
fast assessing,not thread safe |
LinkedList |
if modification is required like addition or deletion |
vector |
if thread safe is priority |
List Iteration
- For loop
for(String word:words)
{
system.out.println(word);
}
- Iterator
Iterator newit = linkedlist.iterator();
while(newit.hasnext())
Type |
Description |
LinkedHashset |
stores the values in insertion order and does not care about sorting |
Treeset |
sorts the order in ascending order, and does not care about insertion order |
hashmap |
unsorted unorder, and it allows key with null value |
HashTable |
synchronized, thread safe, unsorted, unordered, and it doesn't allow key with null value |
LinkedHashMap |
insertion order is maintained, slower insertion n deletion but faster iteration |
TreeMap |
sorted order is maintained and implements navigableMap |
since treeset gives sorted order it implements NavigableSet interface and it has several functions
Set Interface
1. It extends Collection interface
// It can have only unique things.
Set doesnt can add duplicate and can't add element based on position
Different implementation of Sets
1.HashSet : Key part of hashset is hashing function.
Hash is unordered and unsorted
Link elements are linked to each other. order is maintained. (ordered inserted)
Tree : Day is sorted and navigable (Subset can be done)