获取Hazelcast Map的索引值。

huangapple go评论68阅读模式
英文:

Fetch the Hazelcast Map values by index

问题

以下是您要求的翻译内容:

如何按位置获取 hazelcast 缓存的值。

HazelcastInstance hazelCast = Hazelcast.newHazelcastInstance();
IMap<String, String> map = hazelCast.getMap("map1");
map.put("t1", "manu");
map.put("t2", "chite");
map.put("t3", "naveen");
map.put("t4", "vinoda");

我的问题是,是否有一种方法可以通过位置获取值,就像:

map.values().position(1)

输出:

chite

输出:

英文:

How to fetch the hazelcast cache values by the position.

HazelcastInstance hazelCast = Hazelcast.newHazelcastInstance();
IMap&lt;String, String&gt; map = hazelCast.getMap(&quot;map1&quot;);
map.put(&quot;t1&quot;, &quot;manu&quot;);
map.put(&quot;t2&quot;, &quot;chite&quot;);
map.put(&quot;t3&quot;, &quot;naveen&quot;);
map.put(&quot;t4&quot;, &quot;vinoda&quot;);

My question is, Is there any method to fetch the values by the position

like

map.values().position(1)

output:-

chite

output:-

答案1

得分: 1

好的,以下是您要翻译的内容:

在Java中有不同类型的地图实现,您想要的可以通过LinkedHashMap或TreeMap来实现,但是Hazelcast的IMap不支持这一点。实际上,IMap与java Map有很大的区别。

这个类不是一个通用的ConcurrentMap实现!尽管这个类实现了Map接口,但它有意违反了Map的通用契约,该契约规定在比较对象时必须使用equals方法。这个实现不使用equals方法,而是比较对象的序列化字节版本。
此外,存储的值被处理为具有值类型语义,而标准的Java实现将它们视为具有引用类型语义。

英文:

Well, there are different types of map implementation in Java, and what you want can be achieved with a LinkedHashMap or TreeMap, but IMap from Hazelcast does not support this. In fact the IMap is pretty different from a java Map.

> This class is not a general-purpose ConcurrentMap implementation! While this class implements the Map interface, it intentionally violates Map's general contract, which mandates the use of the equals method when comparing objects. Instead of the equals method, this implementation compares the serialized byte version of the objects.
Moreover, stored values are handled as having a value type semantics, while standard Java implementations treat them as having a reference type semantics.

huangapple
  • 本文由 发表于 2020年8月25日 13:43:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/63572682.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定