如何对ArrayList< String>进行排序基于特定的指数范围 [英] How to sort an ArrayList<String> based on specific index range

查看:119
本文介绍了如何对ArrayList< String>进行排序基于特定的指数范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要根据特定的索引范围对字符串的ArrayList进行排序。例如,我在列表中有以下项目: [abc,xyz,pqr,asd] 现在我想从索引1到此列表排序最后一个索引。

My need is to sort the ArrayList of Strings, based on specific index range. For example I have following items in list: ["abc", "xyz", "pqr" , "asd"]Now I want to sort this list from index 1 till last index.

单向我认为我可以从主列表中创建一个具有所需索引范围的子列表,对其进行排序并相应地添加子列表。但我的问题是,有没有可用的API?或任何其他更快的方法来实现这一点。

One way As I think that I can create a sub-list from main list with desired index range, sort it and add the sub-list accordingly. But my question is, is there any API already available for that? Or any other faster way to achieve this.

问候,

Anand

推荐答案

你应该这样做

Collections.sort(yourList.subList(1, yourList.size()));

由于 List.subList 方法返回一个列表的 view ,由 Collections.sort 完成的修改也会影响支持列表。

Since the List.subList method returns a view of the list, modifications done by Collections.sort will affect the backing list as well.

这篇关于如何对ArrayList< String>进行排序基于特定的指数范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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