Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Sorting an ArrayList

Collections.sort(testList);
Collections.reverse(testList);
Comment

java sort arraylist of arraylist

ArrayList<ArrayList<String>> yourList = ...
Collections.sort(yourList, new Comparator<ArrayList<String>>() {
    @Override
    public int compare(ArrayList<String> one, ArrayList<String> two) {
        return one.get(1).compareTo(two.get(1));
    }
});
Comment

how to sort arraylist

Collections.sort(coll); -> helps sort an arraylist.
Comment

arraylist sorter

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class arraylistSorter {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int size;
        do {
            System.out.print("Enter array size (min: 5): ");
            size = input.nextInt();
        } while (!(size >= 5));

        ArrayList<Integer> array = new ArrayList<>(size);

        System.out.println("Enter the numbers: ");
        for (int i = 0; i < size; i++) {
            array.add(input.nextInt());
        }
        System.out.println("Unsorted array: "+ array);

        Collections.sort(array);
        System.out.println("Sorted array: " + array);

        System.out.println("minimum value: ");
        getMinimum(array);

        System.out.println("maximum value: ");
        getMaximum(array);

    }
    private static void getMinimum (ArrayList<Integer> arr) {
        int min = arr.get(0);
        for (int i = 0; i < arr.size(); i++) {
            if (arr.get(i) < min) {
                min = arr.get(i);
            }
        }
        System.out.println(min);
    }

    private static void getMaximum (ArrayList<Integer> arr) {
        int max = arr.get(0);
        for (int i = 0; i < arr.size(); i++) {
            if (arr.get(i) > max) {
                max = arr.get(i);
            }
        }
        System.out.println(max);
    }

}
Comment

how to sort arraylist in java

arrayListObject = (ArrayList<String>) arrayListObject
                     .stream()
                     .sorted()
                     .collect(Collectors.toList());
In
Comment

arraylist sort

return Arrays.stream(words.split(" "))
                .sorted(Comparator.comparing(s -> Integer.valueOf(s.replaceAll("D", ""))))
                .reduce((a, b) -> a + " " + b).get();
Comment

PREVIOUS NEXT
Code Example
Java :: thread java timer 
Java :: java system.out.println not working 
Java :: android studio copy file 
Java :: list java 
Java :: java arraylist with double 
Java :: How to efficiently find the start node of a loop within a singly linked list, in Java? 
Java :: add to list java 
Java :: settext java 
Java :: java cannot find file path 
Java :: array find max in java 
Java :: Syntax of how to create ArrayList in Java 
Java :: remove empty elements from array java 
Java :: create hashmap in java 
Java :: java check if int 
Java :: launch java batch 
Java :: currency formatter java 
Java :: java get element occurrences in a list java 
Java :: java object into list 
Java :: declare function in java 
Java :: java treemap 
Java :: int to char java 
Java :: java return new instance of generic type 
Java :: android arraylist to comma separated string 
Java :: how to covert array into a char 
Java :: default case in Java switch-case 
Java :: java xml element get attribute value 
Java :: convert base64 to pdf object for pdf reader in android studio 
Java :: convert arraylist of integers to array primitive 
Java :: java swing border 
Java :: java random threadlocalrandom double with 2 decimal places 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =