- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to filter an array in Java
You can use List.removeAll() method to filter an array.
example
import java.util.ArrayList; import java.util.List; public class Tester { public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("A"); list.add("B"); list.add("C"); list.add("D"); list.add("E"); list.add("F"); list.add("G"); list.add("H"); List<String> filters = new ArrayList<>(); filters.add("D"); filters.add("E"); filters.add("F"); System.out.println("Original List " + list); list.removeAll(filters); System.out.println("Filtered List " + list); } }
Output
Original List [A, B, C, D, E, F, G, H] Filtered List [A, B, C, G, H]
- Related Articles
- How to filter values from an array in TypeScript?
- How to filter documents based on an array in MongoDB?
- How to filter an array from all elements of another array – JavaScript?
- How to filter array elements in MongoDB?
- JavaScript in filter an associative array with another array
- Filter null from an array in JavaScript?
- JavaScript: How to filter out Non-Unique Values from an Array?
- How to filter values from an array using the comparator function in JavaScript?
- How to filter array in subdocument with MongoDB?
- How to find duplicates in an array using set() and filter() methods in JavaScript?
- How to convert an object array to an integer array in Java?
- How to use map and filter simultaneously on an array using JavaScript?
- Filter an object based on an array JavaScript
- How to create an Array in Java?
- How to initialize an array in Java

Advertisements