aspose file tools*
The moose likes Beginning Java and the fly likes Test for all empty Strings in LinkedHashMap<String,ArrayList<String> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Test for all empty Strings in LinkedHashMap<String,ArrayList<String>" Watch "Test for all empty Strings in LinkedHashMap<String,ArrayList<String>" New topic
Author

Test for all empty Strings in LinkedHashMap<String,ArrayList<String>

albert kao
Ranch Hand

Joined: Feb 04, 2010
Posts: 245
For the LinkedHashMap<String,ArrayList<String> data type, how to find out whether all the Strings in ArrayList are empty/null?

I tried the following code:


Output is:
productList {PC=[], Mac=[]} size 2
st 2
st2 size 2
st2 [[], []]



Why the last line "st2 null " is not displayed?
What should be the code to find out whether all the Strings in st2 are empty/null?
Kevin Workman
Ranch Hand

Joined: Sep 28, 2010
Posts: 151
Are you getting an Exception?
albert kao
Ranch Hand

Joined: Feb 04, 2010
Posts: 245
Kevin Workman wrote:Are you getting an Exception?


I think so.
Kevin Workman
Ranch Hand

Joined: Sep 28, 2010
Posts: 151
albert kao wrote:
Kevin Workman wrote:Are you getting an Exception?


I think so.


...what's the Exception?
Kevin Workman
Ranch Hand

Joined: Sep 28, 2010
Posts: 151
Crossposted: http://www.java-forums.org/new-java/34379-test-all-empty-strings-linkedhashmap-string-arraylist-string.html
albert kao
Ranch Hand

Joined: Feb 04, 2010
Posts: 245
Kevin Workman wrote:
albert kao wrote:
Kevin Workman wrote:Are you getting an Exception?


I think so.


...what's the Exception?


I need to add a try catch block to find out.
My main concern is how to test for all empty Strings in LinkedHashMap<String,ArrayList><String>?
Kevin Workman
Ranch Hand

Joined: Sep 28, 2010
Posts: 151
albert kao wrote:I need to add a try catch block to find out.

What? Why? Just look at the stack trace.

albert kao wrote:My main concern is how to test for all empty Strings in LinkedHashMap<String,ArrayList><String>?

Okay, that's good to know.

The simplest way seems to be looping through and checking each one, no?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

albert kao wrote:For the LinkedHashMap<String,ArrayList<String> data type, how to find out whether all the Strings in ArrayList are empty/null?


For those of us who aren't familiar with your problem, could you clarify whether you just want to find out whether all of the Strings in all of the ArrayList are empty or null? Or do you want to find out separately for each of the ArrayLists whether all of the Strings in it are empty or null?

And probably you should clarify what "empty or null" means; people often use those terms loosely. Even the code you posted suggested you were only interested in nulls and not in empty strings.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38350
    
  23
Thank you for noticing the cross-post, Kevin Workman.
albert kao
Ranch Hand

Joined: Feb 04, 2010
Posts: 245
Paul Clapham wrote:
albert kao wrote:For the LinkedHashMap<String,ArrayList<String> data type, how to find out whether all the Strings in ArrayList are empty/null?


For those of us who aren't familiar with your problem, could you clarify whether you just want to find out whether all of the Strings in all of the ArrayList are empty or null? Or do you want to find out separately for each of the ArrayLists whether all of the Strings in it are empty or null?

And probably you should clarify what "empty or null" means; people often use those terms loosely. Even the code you posted suggested you were only interested in nulls and not in empty strings.


Both.
I want to find out whether all of the Strings in all of the ArrayList are empty or null.
If all of the Strings in all of the ArrayList are not empty or null, then I want to find out separately for each of the ArrayLists whether all of the Strings in it are empty or null, else I do not need to do any more tests.
Empty string means the string is set to "".
Null string means the string is set to null.
Kevin Workman
Ranch Hand

Joined: Sep 28, 2010
Posts: 151
albert kao wrote:Both.

I repeat: The simplest way seems to be looping through and checking each one, no?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Kevin Workman wrote:
albert kao wrote:Both.

I repeat: The simplest way seems to be looping through and checking each one, no?


Since Albert is looking for the presence of two different values (empty and null), there isn't going to be any clever way using the Collections API. The boring solution with loops or iterators is going to be the answer.
albert kao
Ranch Hand

Joined: Feb 04, 2010
Posts: 245
Paul Clapham wrote:
Kevin Workman wrote:
albert kao wrote:Both.

I repeat: The simplest way seems to be looping through and checking each one, no?


Since Albert is looking for the presence of two different values (empty and null), there isn't going to be any clever way using the Collections API. The boring solution with loops or iterators is going to be the answer.


Yes, you are right.
The code should be like this:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Test for all empty Strings in LinkedHashMap<String,ArrayList<String>