有没有一个好的方法让 Map<String, ?>get 和 put 忽略大小写? [英] Is there a good way to have a Map<String, ?> get and put ignoring case?
本文介绍了有没有一个好的方法让 Map<String, ?>get 和 put 忽略大小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有什么好方法可以让 Map
get 和 put 忽略大小写?
Is there a good way to have a Map<String, ?>
get and put ignoring case?
推荐答案
TreeMap 扩展 Map 并支持自定义比较器.
TreeMap extends Map and supports custom comparators.
String 提供了一个默认的不区分大小写的比较器.
String provides a default case insensitive comparator.
所以:
final Map<String, ...> map = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
比较器不考虑区域设置.在其 JavaDoc 中阅读更多相关信息.
The comparator does not take locale into account. Read more about it in its JavaDoc.
这篇关于有没有一个好的方法让 Map<String, ?>get 和 put 忽略大小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文