I am developing an algorithm which relies heavily on the order of elements inside some list, however, that list needs to allow repetition and random access to its elements (without the use of iterator). I've searched for such a thing in java, but the found options were always lacking one of the conditions I mentioned.
Can anyone please suggest me a solution in java for this problem, with a low or moderate time complexity?
If I extended the class of ArrayList and override the method add, and inside the method after addition I call collection.sort (), would that be good regarding time complexity?
I think adding an element takes a constant time since it's directly added to the end of the list, and the sort method takes n logn, so in this case, will insertion take n logn time?
Any help is appreciated.
Thanks.