Java : how to terminate condition check inside for loop -


i have array list shown .

my requirement , if list consists of value "m" in , want terminate condition check (equals check shown ) in loop , want continue further operations in loop

this program

package com;  import java.util.arraylist; import java.util.list;  public class jai {     public static void main(string args[]) {         string flag = null;         arraylist<string> list = new arraylist<string>();          list.add("m");         list.add("m");         list.add("m");         list.add("f");         list.add("m");         list.add("m");         list.add("m");         list.add("f");          (int = 0; < list.size(); i++) {             if (list.get(i).equals("m")) {                 flag = "m";             } else {                 flag = "f";             }             // indicate need continue further operations             // inside loop             system.out.println("hi");          }          if (flag.equals("m"))             system.out.println("this m list");         else             system.out.println("this f list");      } } 

the list consisting of value m in , want treat m list .

the above program simplicity , list contain employee objects in .

i think, looking for

    boolean hasseenm = false;      (int = 0; < list.size(); i++) {         if ( !hasseenm && list.get(i).equals("m")) {             hasseenm = true;         }         // indicate need continue further operations         // inside loop         system.out.println("hi");      }      if (hasseenm)         system.out.println("this m list");     else         system.out.println("this f list"); 

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 -