Jun 18

Maybe you found out already that there is no big difference between Arrays and List – and you are definitely right!

Due to this you can easily turn Lists in Arrays and the other ways around:

String a [] = {“Mailand”, “Berlin”, “Rom”};
List b <String>= Arrays.asList(a);
// changing Array in a List


Object []c = b.toArray(); // Turning an Array in a List of objects
String [] d = new String[3];
d =b.toArray(d);
// Turning a List in a String-Array, but therefore the List need explicitly declared as a List of Strings, otherwise you will get an CompilerError (Type mismatch)

Tagged with:
May 26

As you can imagine, my previous informations about ArrayList are not enough for SCJP.

More or less I wanted to give you first an overview about all the confusing classes and interfaces before going deeper.

ArrayList is quite often used in a polymorphic  way, eg

List d = new ArrayList(); //syntax at older compilers, but still valid
List <String> e = new ArrayList <String> (); // new syntax from java 5

List a = new ArrayList ();
String b =”Meier”;

for (int i = 0; i < a.size(); i++) { System.out.println(a.get(i)); }

Output is


As already mentioned, ArrayList is similar to Array, but much more powerful. One main advantage ist eg non limitatation  of elements and dynamical expand of ArrayList.

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 07

ArrayList have the following characteristics:

  • similar to growing Array
    • elements can easily added/ removed
    • every element has a number/ index starting with 0 for the first element
  • better inserting- and sort-mechanism than arrays
  • growing dynamically – any number of objects can be saved
  • fast iteration
  • fast direct-access
  • ordered (due to array-index)
  • not sorted

In order to work with ArrayLists class java.util.ArrayList needs to be imported.

Here some examples for definition and initialization:

ArrayList <String> a;
a= new ArrayList

ArrayList <Integer> b = new ArrayList();

ArrayList c = new ArrayList();

… and a few more examples for using ArrayList:

a.add (“Hello”); // adding an object
a.size(); // returning array-size
a.get(0); // returning the first element  (in case “Hello”)

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