2

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?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Abheeth Kotelawala
  • 122
  • 1
  • 1
  • 7

1 Answers1

5

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()

ernest_k
  • 44,416
  • 5
  • 53
  • 99
prasingh
  • 452
  • 4
  • 18