• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to avoid empty map val in a list?  RSS feed

 
Rd Dari
Ranch Hand
Posts: 214
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a HashMap with multiple values at runtime. In that map one key has empty value , how to avoid this value to add in a list. some code sample is below:


I do not want to add the empty value in a list please suggest me in a right way.



result in map



result in List



thanks!!
 
Tim Cooke
Marshal
Posts: 4038
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Type are the values in your Map? Unless this is deliberately Java 1.4 code then you should parameterize your Collections which means you define your Map as Map<String, String> or with whatever Types you actually have in there.
 
Rd Dari
Ranch Hand
Posts: 214
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim ,
Thanks for replying me.

I used the isEmpty() to avoid the empty value in a map itself. Its adding only keys those have values.

Thanks.
 
sreenu valireddi
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if map contains string values

Why can't you try like this


list.removeAll(Arrays.asList("", null));

removes empty values and null values from list
 
Campbell Ritchie
Marshal
Posts: 56521
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sreenu sree wrote:if map contains string values

Why can't you try like this


list.removeAll(Arrays.asList("", null));

removes empty values and null values from list
What list?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!