"if" or "where" in for loop of arraylist in java? -


i'm sorry if question bit vague i'll try explain it.

i got code:

    public string tostring() {     string s = "text.\n";      (klus k : alleklussen)     {         s += k.tostring() + ".\n";     }     return s; } 

but want make different loops different conditions. example, "klus" has couple of variables like: status, date etc.

i'm not experienced java yet, possible this:

for (klus k : alleklussen; status = "completed") {..} 

i know wrong i'd show "klus" objects status "completed" , "klus" objects statis "not completed".

thanks , if unclear or used wrong word something, please tell me.

edit:

it should make this:

if (k.getstatus().equals("completed"){   string s = "completed ones \n"   s += k.tostring() + ".\n"; //get completed ones } if (k.getstatus().equals("uncompleted"){       string s = "uncompleted ones \n"       s += k.tostring() + ".\n"; //get uncompleted ones     } 

simply add condition inside for() loop:

for (klus k : alleklussen) {     if (k.getstatus().equals("completed")) {         s += k.tostring() + ".\n";     } } 

from additional information in question, seems following intended:

string completed = "completed ones \n"; string uncompleted = "uncompleted ones \n";  (klus k : alleklussen) {      if (k.getstatus().equals("completed")) {       completed += k.tostring() + ".\n"; //get completed ones     }     else if (k.getstatus().equals("uncompleted")) {        uncompleted += k.tostring() + ".\n"; //get uncompleted ones     } } 

you should consider using stringbuilder create result strings, reduces memory overhead.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -