Jun 30

I already introduced some methods of set bevore:

a.add(11);
a.size();
a.get(0); // CompilerError; working only for List, not for Set
a.remove(11); // deletion of element “11″ (no index!)

Today I would like to go a little bit deeper; let’s have a look on the following example:

System.out.print(a.add(“Mailand”));
System.out.println(” “+a.add(a));
System.out.println(
” “+a.add(new Employee()));
System.out.println(
” “+a.add(“Mailand”));

In case we have defined Set a = new HashSet(); bevore, we get the following output:

true true true false

In case we have definded Set a = new TreeSet(); bevore, we get an CompilerError since TreeSet wants to save the values in an sorted way, which is due to the different objects not possible.

Tagged with:
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 11

HashSet has the following abilities:

  • unsorted
  • unordered
  • management of elements on the base of a fast hash-based datastructure
  • fast inserting and finding of elements
  • HashCode is used for the element to be inserted, therefore: the more efficient HashCode is, the better performance is possible
  • suitable for a collection without duplicates where the order does not matter

Responsible class is  java.util.HashSet.

Definition/ implementation:

HashSet a;
a = new HashSet();

HashSet b = new HashSet();

HashSet c = new HashSet(100);

…  and a few examples for some methods:
a.add(11);
a.size();
a.get(0); // CompilerError; this works only for List, not for Set
a.remove(11); // deletion of element “11″ (no Index!)

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