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?
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.
nullnull then Trim the string and check its lengthExample:
temp == null || temp.trim().length() == 0temp == null || temp.trim().isEmpty(). Note: is empty is internally checking lengthApart 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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With