Home Java Wrapper-class To Retrieve a Particular Object From an ArrayList
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

To Retrieve a Particular Object From an ArrayList

Advertisement
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.

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
Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 28, 2008

Ask Questions?    Discuss: To Retrieve a Particular Object From an ArrayList   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
PARVEEN SAINI
April 2, 2012
FATCH MULTIPLE RECORDS FROM JSONCODE IN J2ME

how to could i get Multiple records from jsonobject. json code is {"BrandNameid":"1","BrandNameid":"2", "BrandNameid":"3"} i am unable to segregate BrandNameid for earch record.
DMCA.com