java - Print out different item from Arraylist one after another -
i try explain problem. have arraylist several strings. have output method:
arraylist<string> testlist = new arraylist<string>(); testlist.add("test1"); testlist.add("test2"); testlist.add("test3"); testlist.add("test4"); public static void output(int testindex) { (int = 0; < testlist.size(); i++) { } system.out.println("domain: "+ testlist.get(testindex)); }
so depending on data need, can use output method , enter values. if enter 0 testindex, print out "test1".
i want make little better though. want whenever call output method, want print out first item. when call again second time, want print out second item. when call third time, want print out third item.. , on.
how do this? can java this? don't want remove arraylist.
you save current position in data member:
private static testindex = 0; public static void output() { system.out.println("domain: "+ chunklist.get(testindex)); ++testindex; }
Comments
Post a Comment