To Retrieve a Particular Object From an ArrayList

In this section you will learn to
retrieve an ArrayList object (that contains multiple elements) using the
get() method. Here is an example that provides the
usage of the get() method in more detail.
Create a class "Get" with an ArrayList .Populate
it with the integer objects. Now retrieve an object( that
is contained in the arraylist) using the get() method.
Here is the Code of the Example :
Get.java:
import java.util.*;
public class Get{
public static void main(String argv[]){
List v = new ArrayList
();
v.addAll(Arrays.asList(new Integer[]{1,2,3,4}));
//cast the int value to an Integer object
Integer iw =(Integer)v.get(2);
System.out.println(iw);
}
}
|
Here is the Output of the Example :
C:\roseindia>javac get.java
C:\roseindia>java get
3 |

|
Current Comments
1 comments so far (post your own) View All Comments Latest 10 Comments:im using servlet, from the servlet im passing the arraylist to the JSP, the arraylist has objects which contain three values, how can i retrieve this object values in JSP
Posted by krishna on Friday, 02.22.08 @ 09:34am | #49380