Is there any simple way (for example library function) to replace fragment of one ArrayList with another ArrayList? What I want to do is:
ArrayList<Byte> fileArr = // some bytes //
ArrayList<Byte> toReplace = // some bytes I want to replace in fileArray //
ArrayList<Byte> window = // window with bytes from file and size of toReplace List //
ArrayList<Byte> replacing = // bytes I want to replace with //
for(int i = 0; i <= (maxElementOfFileArray - sizeOfToReplace); i++){
window = fileArr.subList(i, i+sizeOfToReplace)
if(window.equals(toReplace){
fileArr.replaceAll(i, toReplace, replacing)
}
i= indexOfReplacingListFinishInFileList -1;
}
where the replaceAll function would replace elements of file ArrayList from index where subList toReplace occurs with elements of replacing list, and here's the catch: toReplace and replacing may be diffrent size Lists. Because if they would be the same size I just would do that with set function of ArraList in "for(E e : elements)" . So replace function can change size of file ArrayList it's changing.