GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — java-basics/core-java/strings/ListUsingRemoveAll.java at master · learning-zone/java-basics

Expand file tree

/

ListUsingRemoveAll.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
55 lines (41 loc) · 1.39 KB
/

ListUsingRemoveAll.java

Copy path

File metadata and controls

55 lines (41 loc) · 1.39 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package strings;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.function.Predicate;
public class ListUsingRemoveAll {
// Generic function to remove elements using Predicate
public static <T> List<T>
removeElements(List<T> l, Predicate<T> p)
{
// Create collection using Predicate
Collection<T> collection = new ArrayList<>();
for (T t : l) {
if (p.test(t)) {
collection.add(t);
}
}
// Print the list
System.out.println("Collection to be removed: " + collection);
// Removing 10 using List.removeAll()
// passing a collection
l.removeAll(collection);
// Return the list
return l;
}
public static void main(String[] args)
{
// Create a list with null values
List<String> l = new ArrayList<>(
Arrays.asList("1", "10", "15", "10", "12", "5", "10", "20"));
// Print the list
System.out.println("Original List: " + l);
// Creating a Predicate condition checking for 10
Predicate<String> is10 = i -> (i == "10");
// Removing using Predicate
l = removeElements(l, is10);
// Print the list
System.out.println("Updated List: " + l);
}
}
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.