May 25

It is quite important for SCJP to know exactly differences and similarities of the single classes. Therefore here an overview about the characteristics of the classes:

class abilities
HashMap Connection with a unique key, null keys and multiple null values are allowed 

good performance (dependent on hashCode() implementation, but no order

HashTable Connection with an unique key 

Thread safe

otherwise analogue HashMap

TreeMap Connection with an unique key 

inserting new elements is more time consuming as eg HashMap, but therefore

permanent sorting and

fast, sorted output

LinkedHashMap Connection with an unique key 

faster at adding and deleting elements than HashMap

slower while iterating trough elements

HashSet Uniqueness of values 

fast sorting and finding of elements, but

no order

TreeSet Uniqueness of values 

adding of new elements more time consuming as eg HashSet, therfore

permanent sorting and

fast, sorted output

LinkedHashSet Uniqueness of values, 

high performance at multiple operations

ordered HashSet

ArrayList Values can appear double, 

faster in iterating through elements

Vector Values can appear double 

Thread safe

otherwise analogue ArrayList

LinkedList Values can appear double 

faster in adding and deleting elements than ArrayList

slower in iterating through elements

PriorityQueue “waiting queue” 

sorting by priority

Tagged with:
May 18

Tree Map has the abilities:

  • ordered
  • sorted according to natural order (1,2,3 … A, B, C … a, b, c…)
  • Equals to TreeSet can a individual sorting via Comparable or Comparator be done (more about this in later posts)

responsible class is java.util.TreeMap.

Initialization/ Definition is analogue to other kind of maps:

TreeMap a;
a = new TreeMap <String, Integer>();

TreeMap <Long, Angestellter> b = new TreeMap <Long, Angestellter>();

 

The use is equals to other kind of Maps:

a.put(“Meier”, 12345); // adding Key “Meyer” with value 12345
a.get(“Meier”); // return the to Meyer corresponding value

a.size(); // return map-size, here: 1

a.remove(“Meier”); // deletion

Tagged with:
preload preload preload
http://www.wikio.de Blog Top Liste - by TopBlogs.de Blogverzeichnis - Blog Verzeichnis bloggerei.de Bloggeramt.de Software
Webbhotell Top Blogs