This requires careful thought as it's quite confusing. Did you deliberately create an
array of ArrayLists? I'm asking because I see:
public static ArrayList<Integer>[] a; // 'a' is an array of ArrayLists
...
// ... after entering the size of the table...
a = new ArrayList[size]; // specify that the array has a size of [font=Courier New]size[/font]
for (int i = 0; i < size; i++) {
a[i] = new ArrayList<Integer>(); // instantiate and add ArrayList objects to array 'a'
}
An array of
ArrayList is effectively a 2-dimensional data structure. Is this what you wanted?
In the code for option #2 (Enter an integer),
case 2:
System.out.println("Enter an integer for the table");
int m = input.nextInt();
Hashtable ht=new Hashtable(size); // what is this for?
for ( int i=0; i<a.length; i++ ) {
System.out.println("\nInsert "+a[i]);
insert( new ArrayList(a[i]));
print();
}
break;
The output that you got, "Insert []", is from
System.out.println("\nInsert "+a[i]), where "[]" is from the empty
ArrayList referenced by
a[i]. In the meantime, you created a
Hashtable object (
ht).
ht and the integer that is inputted by the user (
m) are not used (at least not in the code that you posted). What's happening here?
I'd suggest that you give further thought on what you want your code to do, and the data structure that you want to use. Pencil-and-paper might be the right approach for this.
If you need help on using
ArrayLists, you can take a look at a tutorial, e.g.,
Java Collections - List.