Created
December 24, 2021 08:33
-
-
Save gauravkukade/f411ebb758b6cc5b9db47d317fb02eaf to your computer and use it in GitHub Desktop.
A java program to remove the range of elements from the MyArraylist (a class which extends the ArrayList) using the removeRange() method. The removeRange() method is protected and is accessed in class, subclasses and in a package, but not public. Read more at https://coderolls.com/arraylist-removerange-method/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.gaurav.ExProject.ArrayList; | |
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* A java program to remove the range of elements from | |
* the MyArraylist (a class which extends the ArrayList) | |
* using the removeRange() method. | |
* | |
* The removeRange() method is protected and is accessed in class, | |
* subclasses and in a package, but not public. | |
* | |
* @author Gaurav Kukade at coderolls.com | |
* | |
*/ | |
public class MyArrayList extends ArrayList<String> { | |
public static void main(String[] args) { | |
MyArrayList myArrayList = new MyArrayList(); | |
myArrayList.add("Monday"); | |
myArrayList.add("Tuesday"); | |
myArrayList.add("Wednesday"); | |
myArrayList.add("Thursday"); | |
myArrayList.add("Friday"); | |
myArrayList.add("Saturday"); | |
myArrayList.add("Sunday"); | |
System.out.println("Arraylist before removing range of elments:\n"+ myArrayList); | |
myArrayList.removeRange(2, 4); | |
System.out.println("\nArraylist after removing range of elments:\n"+ myArrayList); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Arraylist before removing range of elments: | |
[Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday] | |
Arraylist after removing range of elments: | |
[Monday, Tuesday, Friday, Saturday, Sunday] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment