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 19

There are different kind of Queue, but for SCJP there is only one relevant:

  • PriorityQueue

About Queues:

  • Stack of elements which are taken one by one (typically FIFO – first in, first out)
  • support of all standard Collection Methods
  • additional methods for adding/ removing and to check queue elements
  • A waiting list can take a unlimited amount of elements and returning them back in the order of the insertion. (Similar to supermarkt – those which are first on sales point are served first – first in (there), first out)
  • LinkedList is already expanded with the implementation of queue interface
Tagged with:
May 09

LinkedList has the following abilities:

  • similar to ArrayList with the exception of double linking of elements
  • due to automatical implementation of  java.util.Queue – interface new methods are added, eg
    • poll() // deletion of the oldest (first inserted) value
    • peek () // output of the oldest value
    • offer () // adding values
  • due to the  special build-up especially suitable for  data volumes where  new data is often added or old data deleted
  • is in princible more slowly than ArrayList, adding/ removing is faster

Responsible class is java.util.LinkedList.

Definition/ Implementation is similar to Vector and ArrayList:

LinkedList a;
a = new LinkedList <String>();

LinkedList <Integer> b = new LinkedList ();

LinkedList c = new LinkedList (100); // Attention: CompilerError! This is only possible for Vectors

Using LinkedList is again similar to ArrayList und Vector:
a.add (“Hello”); // adding an object
a.size(); // returning size
a.get(0); // returning first element

Tagged with:
preload preload preload Blog Top Liste - by Blogverzeichnis - Blog Verzeichnis Software
Webbhotell Top Blogs