 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
The set() method of AbstractList class in Java
The set() method of the AbstractList class is used to replace the element at the specified position in this list with the specified element. It returns the element that gets replaced.
The syntax is as follows:
public E set(int index, E ele)
Here, the parameter index is the index of the element to replace, whereas ele is the element to be stored at the specified position.
To work with the AbstractList class, import the following package:
import java.util.AbstractList;
The following is an example to implement set() method of the AbstractlList class in Java:
Example
import java.util.LinkedList; import java.util.AbstractList; public class Demo {    public static void main(String[] args) {       AbstractList<Integer> myList = new LinkedList<Integer>();       myList.add(50);       myList.add(100);       myList.add(150);       myList.add(200);       myList.add(250);       myList.add(300);       myList.add(350);       myList.add(400);       System.out.println("Elements in the AbstractList class = " + myList);       System.out.println("Replaced element = " + myList.set(5, 275 ));       System.out.println("Updated AbstractList = "+myList);    } }  Output
Elements in the AbstractList class = [50, 100, 150, 200, 250, 300, 350, 400] Replaced element = 300 Updated AbstractList = [50, 100, 150, 200, 250, 275, 350, 400]
Advertisements
 