What is the best way to store hostname and port?
I need a map in which I store ID (key) and hostname:port (value). What type of object should I use to store the value?
I tried something like this:
map.put(id, new URI("localhost:2222"));
But after I'd exec开发者_如何转开发uted
entry.getValue().getHost()
and
entry.getValue().getPort()
I got: null and -1.
I need only hostname and port, nothing more.
You could use an InetSocketAddress.
A map. The two lines you show are the same, so I'm not sure why you got different results, but without more code, it's impossible to determine why your lookup failed unless the URI didn't parse correctly.
精彩评论