Java:对不可修改的列表进行排序 [英] Java: Sort an unmodifiable list

查看:178
本文介绍了Java:对不可修改的列表进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是怎么做的?

我已经尝试创建一个新的空列表,然后将不可修改列表的元素复制到它,但我得到不支持的操作错误

I have tried creating a new, empty list, then copying unmodifiable list's elements to it, but I'm getting unsupported operation error.

任何帮助。

推荐答案

空列表使用 Collections.emptyList()

使用List实现的构造函数创建一个新列表,例如 new ArrayList()。您可以将原始列表传递到构造函数中,或者使用 addAll()方法。

Create a new list using the constructor for your List implementation, such as new ArrayList(). You can pass the original list into the constructor or else use the addAll() method.

这篇关于Java:对不可修改的列表进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆