11:03 am - Sunday April 30, 2017

Add Object to specific index of an ArrayList boolean add(int index,E element)

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

                            This method is used to add object at specified index position in an arraylist and this method will return true if the Object is successfully added..

Example Program

import java.util.ArrayList;

public class Fun 
{

public static void main(String[] args)

    {

        ArrayList<String> Student=new ArrayList<String>();

        Student.add("name:");

        Student.add("age:");

        Student.add("email:");

        System.out.println("Enter the details");

        for (String s:Student)

         {

            System.out.println(s);

          }

        Student.add(3,"id:");

        for(String Name :Student)
         {
         
          System.out.println(Name+" ");
         
         }
     }
}

Output

    Enter the details

    name:

    age:

    email:

    id:

BACK

Filed in: Java Examples

Comments are closed.