Program for checking gaps in hierarchy?
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;
  }