gpt4 book ai didi

java - HashMap get() 如何比较键?

转载 作者:行者123 更新时间:2023-12-02 04:09:06 26 4
gpt4 key购买 nike

HashMap get() 的作用机制是什么?

如果我有一个 InetSocketAddress 作为我的 key ,查找是否会返回一个值,该值的 key 与 get() 参数具有相同的 InetAddress 和相同的端口?

最佳答案

Map#get()方法比较两个对象是否 equals()In the case of an InetSocketAddress ,

Compares this object against the specified object. The result is true if and only if the argument is not null and it represents the same address as this object.

Two instances of InetSocketAddress represent the same address if both the InetAddresses (or hostnames if it is unresolved) and port numbers are equal. If both addresses are unresolved, then the hostname and the port number are compared. Note: Hostnames are case insensitive. e.g. "FooBar" and "foobar" are considered equal.

因此,您应该能够拥有 Map<InetSocketAddress,Foo>查找有关特定连接的信息。

关于java - HashMap get() 如何比较键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33966204/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com