Suppose I have a List with the elements
4,7,9,17,24
and I want to insert 11 but to keep them ordered.
So I’d like to do something like
list.add(3, 11), and to get the following list:
4,7,9,11,17,24
but if I do that I get the 17 replaced by 11.
Can you help?
If you are needing an ordered list why not use something like TreeSet. It will use the natural ordering ordering of the Objects or you can pass in your own comparator.