lundi 7 septembre 2015

How to execute a local code from an inner If Statement within an outer if statement in Java

I am parsing through a file and checking for few conditions. If a condition is met, I add a Header then some text based on the the condition. Given that I have too many conditions, I am looking for a way to tell the code go somewhere within the outer if statement to check if the header exists, if it does, come back and write this text. If it doesn't write the header and come back and right this text.

I know the syntax is incorrect, and I am looking for the correct way to accomplish what I am trying to do.

String header;
String str1 ="This is a String I am Checking";
  if (!str1.isEmpty()){
     if (header.isEmpty()){
        addHeader();
        System.out.println(header+"Hello"); 
     }
     void addHeader(){
          if (header.isEmpty()){
             header = "This is a Header";
          }
          else {
                break;
          }
    }
}

Aucun commentaire:

Enregistrer un commentaire