D
D
Denis Sechin2015-02-20 18:37:18
Java
Denis Sechin, 2015-02-20 18:37:18

How to delete all lines with the specified letter [SOLVED]?

Hello, tell me how to get out, there is a code:

ArrayList <String> list = new ArrayList();
      list.add("коля");
      list.add("воля");
      list.add("боля");

I need to delete all lines with the letters "K", how can I do this? I tried to do like this:
for(String s : list){
  if(list.contains("к")){
  list.remove(s);

But the result is zero, please tell me how to be, thanks in advance !!!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
one pavel, 2015-02-20
@onepavel

1. it's not good to delete the elements of the list you are running through
2. you need to look for the character in the string, not in the list

for(String s : list)
    if(s.contains("к"))
        list.remove(s);

3. I would make a copy of the list and run along the copy, and already delete elements from the target

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question