Hi all,
I'm having a bit of a problem with my code. I've created an arraylist method and when values are inputted it prints them one by one.
import java.util.*;
public class ArrayListDemo{
public static void test(int i){
List arrlist = new ArrayList();
arrlist.add(i);
System.out.print(arrlist);
}
public static void main(String[] args) {
test(10);
test(20);
test(30);
test(40);
test(50);
}
}
the array list prints as [10]
[20]
[30]
[40] and so on.
How I want it to print is like,
[10]
[10, 20]
[10, 20, 30] and so on.
I think it's something wrong with the basics , but i just cant figure it out. Any help will be much appreciated.
Thanx for taking the time to read. :)