How do you assign an element to an ArrayList?
Ngày đăng:
04/12/2021
Trả lời:
0
Lượt xem:
67
Java.util.ArrayList.set() MethodAdvertisements Previous Page Next Page DescriptionThe java.util.ArrayList.set(int index, E element) replaces the element at the specified position in this list with the specified element. DeclarationFollowing is the declaration for java.util.ArrayList.set() method Parameters
Return ValueThis method returns the element previously at the specified position. ExceptionIndexOutOfBoundsException If the index is out of range ExampleThe following example shows the usage of java.util.Arraylist.set() method. Live Demo package com.tutorialspoint;
import java.util.ArrayList;
public class ArrayListDemo {
public static void main(String[] args) {
// create an empty arraylist with an initial capacity
ArrayListLet us compile and run the above program, this will produce the following result Number = 15 Number = 20 Number = 25 Number = 22 Printing new list: Number = 15 Number = 20 Number = 55 Number = 22java_util_arraylist.htm Previous Page Print Page Next Page Advertisements |