gpt4 book ai didi

java - 如何制作不区分大小写的 ConcurrentMap?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:55:13 29 4
gpt4 key购买 nike

我该如何实现

class CaseInsensitiveConcurrentMap<V> implements ConcurrentMap<String , V>

就像ConcurrentHashMap<String , V> 一样工作除了不区分大小写地比较键?键不应转换为小写或大写。

请注意 Collections.synchronizedMap(new TreeMap<String, new MyCaseInsensitiveComparator())不是解决方案,因为它不允许并发并且错过了其他方法。

创建不区分大小写的类似字符串的类 equalshashCode也不是一个选项,因为映射必须传递给期望字符串作为键的方法。

最佳答案

你试过吗

ConcurrentMap<String, Object> map = 
new ConcurrentSkipListMap<String, Object>(
String.CASE_INSENSITIVE_ORDER);

关于java - 如何制作不区分大小写的 ConcurrentMap?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6956940/

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