Bookmark Topic Watch Topic
  • New Topic

loading list by index  RSS feed

 
sam bats
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Report post to moderator
I am trying to load the list with index no..(I am using eclipse)

public static void main(String[] args) {

int i;
List list = new ArrayList(20);
for(i=1;i<10;i++ ){
list.add(i, new Integer(i));
System.out.println("values at index " + i +" " + list.get(i) );
}


this is throwing error like --
Exception in thread "main" java.lang.IndexOutOfBoundsException:
Index: 1,Size: 0
at java.util.ArrayList.add(Unknown Source)


can anybody help
 
Aaron Ting
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Report post to moderator
Originally posted by sam bats:
I am trying to load the list with index no..(I am using eclipse)

public static void main(String[] args) {

int i;
List list = new ArrayList(20);
for(i=1;i<10;i++ ){
list.add(i, new Integer(i));
System.out.println("values at index " + i +" " + list.get(i) );
}


this is throwing error like --
Exception in thread "main" java.lang.IndexOutOfBoundsException:
Index: 1,Size: 0
at java.util.ArrayList.add(Unknown Source)


can anybody help



I think this question is of the similar with the one at the Beginner's forum.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Report post to moderator
Originally posted by Aaron Ting:
... I think this question is of the similar with the one at the Beginner's forum.

It sure is, and that one has received responses, so please continue this discussion there.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!