This documentation is archived and is not being maintained.

ArrayList.set Method

Visual Studio 2005

Sets an element in a ArrayList object at the specified index.

Package: java.util

Assembly: vjslib (in vjslib.dll)

public java.lang.Object set(
    int ix,
    java.lang.Object e);



The index of the element to be set.


The element to be set at the specified index.

The element that previously existed at the specified index.

The following example changes an existing element in an ArrayList.

// arraylist_set.jsl

import java.util.*;

public class Program
    public static void main(String[] args)
        // Create an ArrayList containing a simple sentence.
        ArrayList arrList = new ArrayList();
        arrList.add(new String("Today"));
        arrList.add(new String("is"));
        arrList.add(new String("Thursday"));

        // Change the day to Friday.
        arrList.set(2, new String("Friday"));

        Iterator iter = arrList.iterator();
        while (iter.hasNext())
            System.out.print( + " ");

Today is Friday