2

The arraylist that i am working on.

[Bibek Gurung, 9.808112115E9,  , [email protected]]

The code I've tried to check the empty index in an array:

if (!singleRecordExtract.get(2).toString().isEmpty()) {
 //but it passes through the validation
}

I've tried this but somehow, the validation is not working. And I wonder how? Does anyone know the solution or a work around for this problem?

2
  • Why do you use ArrayList instead fields of class? Commented Apr 24, 2015 at 4:08
  • Because this array list is extracted from excel file and I want to set the values to the object of the Class that i want. In order to do so, I am checking for the empty fields. Commented Apr 24, 2015 at 4:13

1 Answer 1

4

The string in the list is probably " ". isEmpty returns false for strings with whitespace. You can fix this by using trim() which removes whitespace from the front and back of a string. This will make your string actually empty.

Sign up to request clarification or add additional context in comments.

1 Comment

I did never think of that...It works perfectly fine now.

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.