• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Intersting ---but must be simple to solve

 
anand chawla
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okie,
I have a Array List which has five elements.
i want to store one element..ie...
3 rd element of array list in a variable that too integer.
so how do i do that.
also if i have store everything in array...how do i?
convert arraylist elements into array.
please can somebody giveme interting url of working examples of utility classes
 
paul sun
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use toArray(Object obj[]) method of Collection framework.
 
Kevin Mukhar
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not really a servlet question. This is a general java question.
If you look at the api javadoc for ArrayList at http://java.sun.com/products/jdk/1.2/docs/api/java/util/ArrayList.html you will see this method:
public Object get(int index)
Returns the element at the specified position in this list.
So you get the third element by calling
Integer i = (Integer) arrayList.get(3);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic