如何将 MultivaluedMap 大写?

发布于 2024-11-15 09:02:20 字数 94 浏览 5 评论 0原文

我有一个 MultivaluedMap 对象,我想将所有键(而不是值)转换为大写。

我设法迭代该对象,但不知道如何重新加载它。

有什么想法吗?

I have a MultivaluedMap object and I want to convert all the keys (not the values) to uppercase.

I managed to iterate through the object, but I can't figure out how to reload it.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

森末i 2024-11-22 09:02:20

为了扩展我对 Ernest 正确答案的评论,以下是我如何实现 remove-and-put 解决方案:

for (String key : new ArrayList<String>(map.keySet())) {
    String upper = key.toUpperCase();
    for (String value : map.remove(key))
        map.add(upper, value);
}

To expand on my comment on Ernest's correct answer, here's how I might implement the remove-and-put solution:

for (String key : new ArrayList<String>(map.keySet())) {
    String upper = key.toUpperCase();
    for (String value : map.remove(key))
        map.add(upper, value);
}
嘿咻 2024-11-22 09:02:20

在处理每个修改后的键/值对时,您必须将其放入新的映射中。最后,您可以返回新地图,丢弃原始地图,也可以 clear() 原始地图并将临时地图中的所有元素复制回原始地图。没有比这更好的方法了。

You'd have to put each modified key/value pair into a new map as you processed it. At the end you could either return the new map, discarding the original, or you could clear() the original and copy all the elements from the temporary map back into the original. There's not going to be any better way to do it than that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文