Details

    • Type: CSR
    • Status: Closed
    • Priority: P3
    • Resolution: Approved
    • Fix Version/s: 11
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Risk:
      minimal
    • Interface Kind:
      Java API
    • Scope:
      SE

      Description

      Summary

      Add a new instance method to java.lang.String that returns true if the string is empty or contains only white space, where white space is defined as any codepoint that returns true when passed to Character#isWhitespace(int).

      Problem

      A traditional solution requires the construction of a new string by stripping the instance string of leading or trailing white space.

      Ex 1.
          // true iff is empty or only contains white space
          boolean blank = string.trim().isEmpty();
      

      In Java 8, the in place solution is awkward in its complexity.

      Ex. 2
          // true iff is empty or only contains white space
          boolean blank = string.codePoints().allMatch(Character::isWhitespace);

      Solution

      The introduction of a new method that avoids any object construction and reduces use complexity.

      Ex 3.
          // true iff is empty or only contains white space
          boolean blank = string.isBlank();
      

      Specification

          /**
           * Returns {@code true} if the string is empty or contains only
           * {@link Character#isWhitespace(int) white space} codepoints,
           * otherwise {@code false}.
           *
           * @return {@code true} if the string is empty or contains only
           *         {@link Character#isWhitespace(int) white space} codepoints,
           *         otherwise {@code false}
           *
           * @see Character#isWhitespace(int)
           *
           * @since 11
           */
          public boolean isBlank() {

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jlaskey Jim Laskey
                Reporter:
                jlaskey Jim Laskey
                Reviewed By:
                Stuart Marks, Sundararajan Athijegannathan, Xueming Shen
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: