Friday, 10 October 2014

Java : Collection Framework : ArrayList (Replace Object)
























Click here to watch in Youtube : https://www.youtube.com/watch?v=5tnwXSwc7QA

ArrayListReplaceExample.java
import java.util.ArrayList;

/*
 * Example of set(int index, E element) method
 */
public class ArrayListReplaceExample
{

    public static void main( String[] args )
    {
        ArrayList<String> arrayList = new ArrayList<String>();
        arrayList.add("Ram");
        arrayList.add("Dave");
        arrayList.add("Peter");
        arrayList.add("Julia");
        arrayList.add("Akram");

        System.out.println("ArrayList : " + arrayList + "\n");

        /*
         * Replace 4th index String object
         */

        arrayList.set(4, "Virat Kohli");

        System.out.println("ArrayList after replacing the element at 4th index : "
                + arrayList + "\n");

    }

}

Output
ArrayList : [Ram, Dave, Peter, Julia, Akram]

ArrayList after replacing the element at 4th index : [Ram, Dave, Peter, Julia, Virat Kohli]


To Download ArrayListDemoReplace Project Click the below link

https://sites.google.com/site/javaee4321/java-collections/ArrayListDemoReplace.zip?attredirects=0&d=1

See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge