![]() ith element with the ith element from the last you need to do this till you reach the midpoint of the array. So you should convert your byteArray into a List either by doing Arrays.asList(byteArray) or by creating an List object and adding byte values into it. In short swap the 1st element with the 1st element from last, second element with the second element from last i.e. The original array gets replaced by the reversed array. Method 3: Recursive in-place reversing of the original array. Method 2: Actual in-place reversing of the original array. This will be repeated until all the elements are swapped. Method 1: Just print the array in reverse order. ![]() Collections.reverse () method is such an API. In this method, we swap the first element of array with the last element of the array, the second first with the second last, the third first with the third last and so on. ![]() To reverse an array, swap the first element with the last element and the second element with second last element and so on if the array is of odd length leave the middle element as it is. Well swap elements symmetrically from the start and end of the array, gradually moving towards the center, until the entire array is reversed. The easiest way to reverse the array is to use the existing APIs built for this very purpose.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |