Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.isBlank() Not Recognized in Java NetBeans [duplicate]

Tags:

java

swing

I tried implementing .isBlank() to omit whitespace. The netBeans IDE 11.0 (and 8.2) shows "cannot find symbol" error.

When this project is opened from another PC it works!

public FormulaElement parseFormula(String text) {

        StringTokenizer tokenizer = new StringTokenizer(text, "+-*/^√()!πe% \t", true);

        Vector<Object> vec = new Vector<>();
        while (tokenizer.hasMoreTokens()){
        String temp= tokenizer.nextToken();
        //omitting whitespace
        if(temp.isBlank() == true){
           continue;
        }

How can I fix the issue?

like image 711
Abheeth Kotelawala Avatar asked Dec 07 '25 14:12

Abheeth Kotelawala


1 Answers

To collect all the comments and putting some additional information. Here we are:

JDK 11

String class have isBlank() for checking blank string.

Less then JDK 11

There is no built in function. We have to tackle it is different way.

  1. First check whether the string is null
  2. If it is not null then Trim the string and check its length

Example:

  1. temp == null || temp.trim().length() == 0
  2. or, temp == null || temp.trim().isEmpty(). Note: is empty is internally checking length

Apart from this, there are some 3rd party Libs available that do this for us Like,

Apache common lang

It has various method for String. For our case StringUtils.isBlank is suitable candidate. I recommend you to read other string related methods too.

Guava

This lib also provide methods for string.

Example: Strings.isNullOrEmpty()

like image 132
prasingh Avatar answered Dec 09 '25 02:12

prasingh