java - Swap sublists in a List<MyObject> -


is there easy method swap 2 sublists in list. example:

[0 1 2 3 4 5 6 7 8 9 10 11] --> [0 1 8 9 10 4 5 6 7 2 3 11]   --> sublist1= [2 3]   --> sublist2= [8 9 10] 

if okay indexes, can done using sublist function multiple files , creating new list object shown below...

list<integer> newlist = new arraylist<integer>(mylist.sublist(0, 4)); newlist.addall(mylist.sublist(7, 9)); newlist.addall(mylist.sublist(4, 7)); newlist.addall(mylist.sublist(9, 12)); 

here swapping index 4 6 indexes 7 8

if want using elements, first use elements find indexes of sublist , use above procedure.

don't confused endindex of sublist function... fromindex - low endpoint (inclusive) of sublist toindex - high endpoint (exclusive) of sublist if mention 7,9 in sublist function means elements index 7 till elements below index 9.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -