

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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 subList() method of AbstractList class in Java
<p>The subList() method returns a part of this list between the specified fromIndex, inclusive, and toIndex, exclusive. Get a sublist using the method by setting the range as the two parameters.</p><p>The syntax is as follows.</p><pre class="result notranslate">public List<E> subList(int fromIndex, int toIndex)</pre><p>Here, the parameter fromIndex is the low endpoint (inclusive) of the subList and toIndex is the high endpoint (exclusive) of the subList.</p><p>To work with the AbstractList class, import the following package.</p><pre class="result notranslate">import java.util.AbstractList;</pre><p>The following is an example to implement subList() method of the AbstractlList class in Java.</p><h2>Example</h2><pre class="prettyprint notranslate">import java.util.ArrayList; import java.util.AbstractList; public class Demo { public static void main(String[] args) { AbstractList<Integer> myList = new ArrayList<Integer>(); myList.add(5); myList.add(20); myList.add(35); myList.add(47); myList.add(55); myList.add(70); myList.add(100); myList.add(140); myList.add(180); myList.add(250); System.out.println("Elements in AbstractList = " + myList); List<Integer> list = myList.subList(5, 7); System.out.println("Sublist of AbstractList: "+ list); } }</pre><h2>Output</h2><pre class="result notranslate">Elements in AbstractList = [5, 20, 35, 47, 55, 70, 100, 140, 180, 250] Sublist of AbstractList: [70, 100]</pre>
- Related Questions & Answers
- The addAll() method of AbstractList class in Java
- The lastIndexOf() method of AbstractList class in Java
- The indexOf() method of AbstractList class in Java
- The equals() method of AbstractList class in Java
- The clear() method of AbstractList class in Java
- The iterator() method of AbstractList class in Java
- The listIterator() method of AbstractList class in Java
- The get() method of AbstractList class in Java
- The set() method of AbstractList class in Java
- The hashCode() method of AbstractList class in Java
- The remove() method of AbstractList class in Java
- The listIterator() method AbstractList class in Java at a specified position
- The subList() method of AbstractSequentialList in Java
- What is AbstractList Class in Java?
- How to add elements to AbstractList class in Java?
Advertisements