Java List of Lists

I’m programming a list, containing lists of strings.

That’s how it looks like:

List<List<String>> WPL = new ArrayList<List<String>>();
List<String> WP = new ArrayList<String>();

WP.add("A");
WP.add("B");
WPL.add(WP);

WP.clear();

WP.add("C");
WP.add("D");
WPL.add(WP);

for(List<String> a : WPL) {
    System.out.println(a.indexOf(a));
    for (String i : a)
    {
        System.out.println(i);
    }

}

(The lists will be generated automized later and much longer) All I get as a response is

-1
C
D
-1
C
D

What I need is

0
A
B
1
C
D

What am I doing wrong?


Download java.list.of.lists.zip
Direct Link


Download


Download java.list.of.lists.zip
Mediafire


Download


Download java.list.of.lists.zip
Filedwon


Download

Both comments and pings are currently closed.

Comments are closed.