“if” or “where” in for loop of arraylist in java?

Forum

New Member
I'm sorry if the question is a bit vague so i'll try to explain it.I got this code: \[code\] public String toString(){ String s = "text.\n"; for (Klus k : alleKlussen) { s += k.toString() + ".\n"; } return s;}\[/code\]But I want to make different loops for different conditions.For example, "Klus" has a couple of variables like: status, date etc.I'm not very experienced with java yet, but would it be possible to do something like this:\[code\]for (Klus k : alleKlussen; status = "completed"){..}\[/code\]I know this is wrong but I'd like it to show all "Klus" objects where the status is "completed" and all "Klus" objects where the statis is "not completed".Thanks and if anything is unclear or I used the wrong word for something, please tell me.Edit:It should make something like this:\[code\]if (k.getStatus().equals("completed"){ String s = "completed ones \n" s += k.toString() + ".\n"; //get all completed ones}if (k.getStatus().equals("uncompleted"){ String s = "uncompleted ones \n" s += k.toString() + ".\n"; //get all uncompleted ones }\[/code\]
 
Top