I'm looking for a collection that would be some sort of a list that allows gaps. The objectives are:
- every element has some index in the collection that is meaningful.
- the collection is to be sparse and not continuous; its size should return the number of proper elements, hence the workaround of initializing with
null
wouldn't work. subList
method is desirable to access sublists according to index intervals
Sample use case:
List<Integer> list = /* ? */;
list.add(0,5);
list.add(1,4);
list.add(5,3);
for( Integer i : list )
{
System.out.print( i + " " );
}
/* desired output : "5 4 3 "*/