Java ArrayList set Example

ArrayList class set method example. This example shows you how to use set method.


ArrayList class set method example.set(int index, E element) Replaces the element at the specified position in this list with the specified element.

Here is the code

/**
 * @ # Set.java
 * A class repersenting use to Set method of ArrayList class in java.util package
 * version 14 May 2008
 * author Rose India 
 */
import java.util.*;

public class Set {

    public static void main(String args[]) {
        List arrlist = new ArrayList();
        int i = 0;
        String str = "Rose";

        //Add the specified element to the end of this list.
        arrlist.add(i);
        arrlist.add(str);
        arrlist.add("India");
        System.out.println("arrlist = " + arrlist);

        //set a element at 0 position
        arrlist.set(0"New Element ");
        System.out.println("arrlist = " + arrlist);
    }
}

Output
arrlist = [0, Rose, India]
arrlist = [New Element , Rose, India]

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US