How do I reverse an int array in Java?

前端 未结 30 2359
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-21 07:18

I am trying to reverse an int array in Java.

This method does not reverse the array.

for(int i = 0; i < validData.length; i++)
{
    int temp =          


        
30条回答
  •  无人及你
    2020-11-21 08:07

    public class ArrayHandle {
        public static Object[] reverse(Object[] arr) {
            List list = Arrays.asList(arr);
            Collections.reverse(list);
            return list.toArray();
        }
    }
    
        

    提交回复
    热议问题