Benny's Blog
4. September 2011

With this post I just want to show how to convert a Java collection into an array and how to convert a wrapper class array into an array of the corresponding primitive data type. As a bonus I will show how to iterate over an ArrayList.

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 public static void main(String[] args)
  {
    // Java collection (ArrayList) with Floats
    ArrayList<Float> someFloats = new ArrayList<Float>();
    someFloats.add(3.72f);
    someFloats.add(28.07f);
    someFloats.add(2011f);
    // Convert ArrayList into an array
    Float[] floatWrapperArray = someFloats.toArray(new Float[someFloats.size()]);
    float[] floatArray = new float[floatWrapperArray.length];
    // Transfer array of Wrapper type (Float) into array of primitive data type (float)
    for (int i = 0; i < floatArray.length; i++)
    {
      floatArray[i] = floatWrapperArray[i].floatValue();
    }
    // 1. Float ArrayList
    System.out.println("1. Float ArrayList");
    for (Iterator iterator = someFloats.iterator(); iterator.hasNext();)
    {
      Float currentFloat = (Float) iterator.next();
      System.out.println(currentFloat);
    }
    // 2. Float array
    System.out.println("2. Float array");
    for (int i = 0; i < floatWrapperArray.length; i++)
    {
      System.out.println(floatWrapperArray[i]);
    }
    // 3. float array
    System.out.println("3. float array");
    for (int i = 0; i < floatArray.length; i++)
    {
      System.out.println(floatArray[i]);
    }
  }

Output

1
2
3
4
5
6
7
8
9
10
11
12
1. Float ArrayList
3.72
28.07
2011.0
2. Float array
3.72
28.07
2011.0
3. float array
3.72
28.07
2011.0
4. September 2011

Bei der Suche nach geeigneten Tutorials zu regulären Ausdrücken bin ich auf dieses fantastische Video gestoßen:

Wer lieber lesen möchte, dem empfehle ich das Java Regex Tutorial von Lars Vogel. Zum Testen von regulären Ausdrücken eignet sich regexpal.

4. September 2011

Zwischen 0-6 Uhr kann man beim Mindfactory Midnight-Shopping versandkostenfrei bestellen.

1. September 2011

This code shows how to draw a simple triangle with OpenGL ES (OpenGL 1.0) on the screen of an Android mobile device. It is based on the tutorial OpenGL ES Tutorial for Android – Part I – Setting up the view from the Jaway Team Blog. To keep things simple I decided to implement only the necessary parts and to comment things that are not obvious. Please note that the class GL10 stands for OpenGL 1.0.

…weiterlesen

27. August 2011

Der Mozilla Firefox beherrscht die wahnsinnig praktische Funktion, bei Eingabe eines Suchwortes in der Adresszeile, direkt auf Google danach zu suchen. Man muss es ihm/ihr nur beibringen. Das geht wie folgt:

  1. about:config in die Adresszeile eingeben
  2. keyword.URL im “Filter” der Konfiguration eingeben
  3. http://www.google.de/search?ie=UTF-8&q= als String für die keyword.URL eingeben

Vielen Dank an den Beitrag “Google-Suche in Adresszeile” aus dem Männerblog.

21. August 2011

In Linux können Prozesse mit dem Tool screen im Hintergrund ausgeführt werden. Dazu sind nur folgende Befehle aus der Konsole nötig:

1
2
3
screen -S mein_prozess
Strg+A+D
screen -rx mein_prozess

Erklärung:

  1. Legt einen neuen Hintergrundprozess an, der Name für mein_prozess ist frei wählbar
  2. Mit der Tastenkombination Strg+A+D (Tasten zügig nacheinander drücken), kann man aus sceen wieder ins Terminal wechseln
  3. Mit dem Aufruf von screen -rx kann wieder zum Hintergrundprozess zurückgekehrt werden