This is some information on the Java 6 certification that I prepare. This information is not very well structured and it is most of the time an answer to the questions that come when I read the SCJP 6 book (Bates and Sierra). *** AS OF 5 OF MARCH 2010, I AM SCJP 6.0 ***

Friday, February 19, 2010

32 - arrays - Java 1.6

I find the following very fascinating...

package basic;

public class Main {

    public static void main(String[] args) {

        Object d = new Long[4];
        Object[] e = (Object[]) d;
        System.out.println("e[0] : " + e[0]);

        Long[] f = (Long[]) d;
        System.out.println("\nf[0] : " + f[0] + "\n");


        Long[] g[] = {{1L, 2L}, {1L}};
        for (int i = 0; i < g.length; i++)
            for (int j = 0; j < g[i].length; j++)
                System.out.println(g[i][j]);
       
        System.out.println("");
        String[] s = new String[4];
        int i=0;
        for(String s1:s)
            System.out.println(i++ + ":" + s1);

        System.out.println("");
        int []t[] = new int[5][6];
        for(int k=0; k < t.length; k++) {
            int m = 0;
            for(int l:t[k]) {
                System.out.println(m++ + ":" + l);
            }
            System.out.println("");
        }
    }
}

run:
e[0] : null

f[0] : null

1
2
1

0:null
1:null
2:null
3:null

0:0
1:0
2:0
3:0
4:0
5:0

0:0
1:0
2:0
3:0
4:0
5:0

0:0
1:0
2:0
3:0
4:0
5:0

0:0
1:0
2:0
3:0
4:0
5:0

0:0
1:0
2:0
3:0
4:0
5:0

BUILD SUCCESSFUL (total time: 0 seconds)

No comments:

Post a Comment

Followers