Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Reverse array java

import java.util.Arrays; 

public class Main {
    public static void main(String[] args) {
        int[] numbers = {1, 2, 3, 4, 5};
        reverse(numbers);
        /*
            output is:
                Array = [1, 2, 3, 4, 5]
                Reversed array = [5, 4, 3, 2, 1]
        */
    }
    
    public static void reverse(int[] array) {
        System.out.println("Array = " + Arrays.toString(array));
        int maxIndex = array.length - 1;
        int halfLength = array.length / 2;
        for (int i = 0; i < halfLength; i++) {
            int temp = array[i];
            array[i] = array[maxIndex - i];
            array[maxIndex - i] = temp;
        }
        System.out.println("Reversed array = " + Arrays.toString(array));
    }
}
Comment

reverse array java

//With Commons.Lang, you could simply use

ArrayUtils.reverse(int[] array)

// For reversing subarray
ArrayUtils.reverse(int[] array,int startIndexInclusive, int endIndexExclusive)


Comment

reverse int array java

import java.util.*;
import java.util.stream.Collectors;

int[] array = new int[] {23, 54, 12};
List<Integer> list = Arrays.stream(array).boxed().collect(Collectors.toList());
Collections.reverse(list);
array = list.stream().mapToInt(x -> x).toArray();
//array = [12,54,23]
Comment

reverse in jaav

// my linkedin : https://www.linkedin.com/in/vaalarivan-prasanna-3a07bb203/
list = new ArrayList<int> {3, 4, 7};  //initialising a list
Collections.reverse(list);  //reverses a List or an ArrayList
//now, list is {7, 4, 3}
Comment

reverse java

public void reverse()
    {
        for (int i = 0; i < size/2; i++)
        {
            int temp = get(i);
            elementData[i] = elementData[size-i-1];
            elementData[size-i-1] = temp;
        }
    }
Comment

java reverse array

public void reverseArray(int[] arr) {
	int len = arr.length;
    int left = 0, right = len - 1 - left;
    while (left < right) {
        swap(arr, left, right);
        left++;
        right--;
    }
}
    
private void swap(int[] arr, int left, int right) {
    int tmp = =arr[left];
    arr[left] = arr[right];
    arr[right] = tmp;
}
Comment

array reverse in java

        int[] xr = {1, 2, 3, 4, 5};

        System.out.print("[");
        for (int i = xr.length - 1; i >= 0; i--) {
            System.out.print(xr[i] + ", ");
        }
        System.out.println("]");
    }
Comment

java reverse a array

// Algorithm
wide_floating_point e() {
  unsigned n = 33;
  my_uint128 num = 1;
  my_uint128 den = 1;
  for (unsigned i=1; i <= n; i++) {
    num = num*i + 1;
    den = den*i;
  }
  return (wide_floating_point) num/fact;
}
Comment

java reverse array

WWWWW-
S---W-
W-W-W-
W-W---
E-W-W-
WWWWW-
Comment

PREVIOUS NEXT
Code Example
Java :: nextint java 
Java :: quicksort java 
Java :: java spring set private field in test 
Java :: deifine an integer array in java 
Java :: like in cypher query 
Java :: android arraylist to comma separated string 
Java :: java stream inner join two lists 
Java :: get free player inventory slots spigot 
Java :: exceptions in java 
Java :: java get year difference between two dates 
Java :: windows Jmeter java.net.BindException: Address already in use: connect 
Java :: bulkwrite mongodb array of objects 
Java :: potenzieren java 
Java :: set gamemode of player spigot 
Java :: recursion of numbers in decending order in java 
Java :: how to merge two arrays in java 
Java :: why are my if statements not working with inputs in java 
Java :: what is static method in oop 
Java :: array de meses java 
Java :: java program to convert milliseconds to minutes and seconds 
Java :: sort arrays by first element java 
Java :: android studio json parser 
Java :: Java if...else 
Java :: null java 
Java :: how to compare doubles in java 
Java :: radiogroup get selected item android 
Java :: java store data 
Java :: java scanner next() 
Java :: Java @Deprecated annotation 
Java :: streams in java 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =