Program for checking gaps in hierarchy? In my data I have few hierarchy values - example address

Name -&gt; Street -&gt; City -&gt; County -&gt; State -&gt; Country

The validation I need is: if a value in the above hierarchy is present, then all the previous/higher order values should be present.
Below is a valid case

Name -&gt; Street -&gt; City -&gt; State
This is valid even though there is no country - as it is last in the order

and below is an invalid case

Name -&gt; Street -&gt; State -&gt; Country
This is invalid as there is no City Which is of higher order than state and country.

The below code helped me in doing the checks. Can this be simplified further? I want to get rid of the last dummy return statement. (To the best of my knowledge, it is difficult to get rid of it. But there are more people far more knowledgeable than me.)
 package com.example.demo;

public class SimplyfyHierarchyCheck {

    public static void main(String[] args) {

        String a=&quot;a&quot;, b=&quot;b&quot;, c=&quot;c&quot;, d=&quot;d&quot;; 

        SimplyfyHierarchyCheck shc = new SimplyfyHierarchyCheck();
        System.out.println(shc.isGapLessHierarchy(&quot;a&quot;, b, &quot;&quot;, &quot;&quot;) );
    }

    //can this method be made even more concise.
    private boolean isGapLessHierarchy(String... args) { //Hierarchy 
        boolean isGapLess=true;

        for(int i=args.length-1; i&gt;=0; i--) {
            if(args[i].isBlank() )  //nothing to check 
            {
                continue;
            }
            for(int j=i-1; j&gt;=0; j--) {
                if(args[j].isBlank() )  //gap found i.e false 
                {
                    return false;
                }
            }
        }
        return isGapLess; //dummy return // am required to return true or false // can i get rid of this
    }

}
As a long-term Java programmer, I know that most of my time will be spent in maintenance.
On that basis I prefer simple code that expresses its purpose clearly to clever, concise, unclear code.
With that context in place here's some basic comments.
 String a=&quot;a&quot;, b=&quot;b&quot;, c=&quot;c&quot;, d=&quot;d&quot;; 


It's not the Java way to do multiple declarations together - I'd
split these.

They are constants not variables, so they should be &quot;static final&quot; (and UPPERCASE).

Three of them are not used, so delete them.
System.out.println(shc.isGapLessHierarchy(&quot;a&quot;, b, &quot;&quot;, &quot;&quot;) );

Why do you mix use of a constant and a literal? As a maintenance
programmer looking at your code I'm now wondering whether this has
some significance.


Now to your &quot;isGapLessHierarchy()&quot; method:

The method has no dependency on an object, so it should be &quot;static&quot;
Never call anything &quot;args&quot; (other than perhaps the arguments to a main method). Give your method parameters meaningful names. How about &quot;hierarchyElements&quot; in this case?
(Almost) Never use 'i' and 'j' as indexes. Use something meaningful.
Going forwards through a list is (IMHO) clearer than going backwards. Your condition can be expressed as &quot;a gap should never be followed by a non-gap&quot;, which allows us to go forwards.

Here's my code using your pattern, with some cleanup and adding a more extensive set of tests (I couldn't be bothered with Junit in this case, but you probably should).
  public class HierarchyCheck {

  public static void main(String[] args) {
    String[][] testCases = new String[][]{
      new String[]{&quot;Name&quot;, &quot;Street&quot;, &quot;City&quot;, &quot;County&quot;, &quot;State&quot;, &quot;Country&quot;},
      new String[]{&quot;Name&quot;, &quot;Street&quot;, &quot;City&quot;, &quot;County&quot;, &quot;State&quot;, &quot;&quot;},
      new String[]{&quot;Name&quot;, &quot;Street&quot;, &quot;City&quot;, &quot;County&quot;, &quot;&quot;, &quot;Country&quot;},
      new String[]{&quot;Name&quot;, &quot;Street&quot;, &quot;&quot;, &quot;County&quot;, &quot;State&quot;, &quot;Country&quot;},
      new String[]{&quot;Name&quot;, &quot;&quot;, &quot;City&quot;, &quot;&quot;, &quot;State&quot;, &quot;Country&quot;},
      new String[]{&quot;Name&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;}
    };

    for (String[] testCase : testCases) {
      System.out.format(&quot;%s %s gapLess%n&quot;, 
                        Arrays.toString(testCase),
                        isGapLessHierarchy(testCase) ? &quot;is&quot; : &quot;is not&quot;);
    }
  }

  private static boolean isGapLessHierarchy(String... hierarchyElements) {

    // Find the first gap
    int firstGap = 0;
    for (firstGap = 0; firstGap &lt; hierarchyElements.length; firstGap++) {
      if (isBlank(hierarchyElements[firstGap])) {
        break;
      }
    }

    // Is there a non-gap after the first gap?
    for (int nonGap = firstGap + 1; nonGap &lt; hierarchyElements.length; nonGap++) {
      if (!isBlank(hierarchyElements[nonGap])) {
        // There is, so it's not gapless
        return false;
      }
    }

    // Definitely gapless
    return true;
  }

  // We don't have Java 11 for the String.isBlank() method, so fake it!
  private static boolean isBlank(String string) {
    return (string == null) || (string.trim().length() == 0);
  }
}

However, I'd probably have gone for a simpler, arguably cruder approach.
  private static boolean isGapLessHierarchy(String... hierarchyElements) {

    boolean seenGap = false;

    for (String hierarchyElement : hierarchyElements) {
      if (isBlank(hierarchyElement)) {
        seenGap = true;
      }
      else {
        if (seenGap) { // gap followed by non-gap
          return false;
        }
      }
    }

    // Definitely gapless
    return true;
  }