Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java equivalent of C# Sorted List [duplicate]

Possible Duplicate:
sorted collection in java

I was wondering if Java has its own version of Sorted List, or if I need to create my own. I want the list to automatically update itself if something is removed. For example, if I remove something from the start of the list, or even in the middle, I want everything behind it to move up in the list, and the remaining null value space to be removed.

like image 391
Hani Honey Avatar asked Dec 28 '22 22:12

Hani Honey


1 Answers

If you're really after the equivalent of a .NET SortedList, which is actually a map ordered by its keys, then the closest equivalent is probably TreeMap. That's actually more like SortedDictionary than SortedList, given that it's a tree rather than just a list, but it's probably the closest available option.

However, what you've described is more like ArrayList, which is similar to .NET's List<T>.

like image 141
Jon Skeet Avatar answered Dec 30 '22 12:12

Jon Skeet