I have to make a method that can reverse all elements of ArrayList ... For exmaple, if my list have <12 1 34 56 43> elements. then it should reverse the whole list. <43 56 34 1 12>. I've tried this method, but it doesn't work. Here is the method
public void reverse() {
int size=0;
for (int i = 0, j = size - 1; i < size && j >= 0; i++, j--)
{
int temp = j;
j = i;
i = temp;
}
}
when I call this method list.revese(). it doesn't reverse the list. Can anyone please help me out!!!
getandsetmethods in order to actually modify the list.List#reversedin Java 21+.