Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to remove square brackets from ImmutableMultimap.keys()

Tags:

java

guava

While performing the following:

ImmutableMultimap<Something, Something> map;
//Say I insert "Hello", "5" to the map
System.out.println(map.keys().toString());

This prints [Hello] So when I do

if(map.keys().toString().equals("Hello"))

it always fails. I don't want to do

if(map.keys().toString.equals("[Hello]")

Is there a way to display the result without the square brackets?

like image 960
noMAD Avatar asked Mar 18 '26 14:03

noMAD


1 Answers

You should never ever use toString() for anything serious! This method is meant for people inspecting what's going on (e.g. in debugger) and for nothing else.

Moreover, there are no brackets there in. map.keys() is a collection and it's toString() method works like it should for collections. You'd better replace your test by testing map.keys.size() == 1 and then checking the only element.

like image 157
maaartinus Avatar answered Mar 20 '26 22:03

maaartinus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!