英文:
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<String, String> map = hazelCast.getMap("map1");
map.put("t1", "manu");
map.put("t2", "chite");
map.put("t3", "naveen");
map.put("t4", "vinoda");
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论