0

Very tired this morning so if this is obvious then thats my excuse !!!

i am using a buffered reader to read through a csv file - but i dont want to add any empty spaces, as in

" "

the problem is - when i read the line i am checking if the string length is > 0, if so then add, however the string " " is of length 4 - even tho its empty

is there a better check i can do

thanks

3 Answers 3

6
s.trim().isEmpty()
Sign up to request clarification or add additional context in comments.

Comments

3

could trim the input :-)

trim()
      Returns a copy of the string, with leading and trailing whitespace omitted.

karl

Comments

2

I usually prefer, StringUtils of commons-lang, or something like that. Actually, you require this kinda check every now and then, plus there are few variants and all are null-safe. Namely, StringUtils.isBlank(String str), StringUtils.isNotBlank(String str), StringUtils.isEmpty(String str), StringUtils.isNotEmpty(String str), StringUtils.trimToEmpty(String str), and StringUtils.trimToNull(String str).

1 Comment

+1 for that - I use StringUtils.defaultString() (both the unary and binary versions) so often now that I feel it should be part of the language.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.