Answers for "reverse list java"

5

how to reverse order of arraylist

ArrayList<Integer> arrlist = new ArrayList<Integer>();
//This is how to reverse arrlist's oringinal order.
Collections.reverse(arrlist);

//This is how to sort in a reverse order
 Collections.sort(arrlist, Collections.reverseOrder());
Posted by: Guest on September-06-2020
5

reverse number in java

public class ReverseNumber {
    public static void main(String[] args) {
        int num = 1234, reversed = 0;

        while(num != 0) {
            int digit = num % 10;
            reversed = reversed * 10 + digit;
            num = num / 10;
        }
        System.out.println("Reversed Number: " + reversed);
}}
Posted by: Guest on May-25-2020
5

how to reverse a list in java

List<String> stringList = Arrays.asList("A", "B", "C");
    Collections.reverse(stringList);
    assertThat(stringList).containsExactly("C", "B", "A");
Posted by: Guest on March-19-2020
3

Collections reverse on java

//import java.util.Collections;
//create and add items to list
Collectons.reverse(list);
Posted by: Guest on September-06-2020
1

Arraylist reverse in java

public static void main(String[] args) {

        ArrayList<Integer>list = new ArrayList<>();
        for(int i = 1; i < 6; i++){ // bu element index degil.
            list.add(i);
        }
        System.out.println(list); // [1, 2, 3, 4, 5]

        for (int i = list.size()-1; i >= 0; i--) {
            int each = list.get(i);  // unboxing
            System.out.print(each + " "); // 5 4 3 2 1
        }
Posted by: Guest on June-04-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language