0

I have an ArrayList that's populated with sentences but need certain elements to be removed based on if they contain a certain integer.

Here's what my ArrayList looks like

[Savings 12345678 0.60, Checking 98765432 0.01, Deposit 98765432 300, Transfer 98765432 12345678 300]

I want to remove elements that include 98765432

(Checking 98765432 0.01, Deposit 98765432 300, and Transfer 98765432 12345678 300)

but keep Savings 12345678 0.60.

2
  • 1
    Post your code. What is the ArrayList of? Commented Dec 3, 2021 at 2:35
  • 1
    Filtering a list in Java - I'd recommend scrolling down to the "Filtering a list with Java 8 streams" section Commented Dec 3, 2021 at 2:35

2 Answers 2

0

You can use Java Streams' Filter method to filter the List using a Predicate.

https://www.geeksforgeeks.org/stream-filter-java-examples/

Quick Example: list = list.stream().filter(num -> !(num + "").contains("98765432"));

Sign up to request clarification or add additional context in comments.

1 Comment

Can you please little more information, like syntax etc. So it could better to understand beginner at same place
0

Perform a regular loop inside each element from the ArrayList.Then use the .contain function to search for a specific value at each element in the ArrayList(in your case a specific number:98765432).Finally over-write that element with a new string startIndex and endIndex.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.