开发者

What is the best way to store hostname and port?

开发者 https://www.devze.com 2023-04-13 05:01 出处:网络
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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号