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 :: sort a list with custom comparator java 
Java :: java_remove last char 
Java :: java command to start jenkins 
Java :: Area of a Circle in Java Programming 
Java :: spark write partitionby 
Java :: float java 
Java :: infinite for loop java example 
Java :: work with arrays java 
Java :: hashmap get value by key java 
Java :: convert arraylist to array int 
Java :: how to add a listener to a toggle group radio buttons javafx 
Java :: haxe interface 
Java :: binary search java 
Java :: valueof in java 
Java :: print symbol in pyramid shape in java 
Java :: latest android version 
Java :: Java Create a BufferedWriter 
Java :: java comparing-two-csv-files-in-java 
Java :: get imei android programmatically android 10 
Java :: sorting collections with comparator java 
Java :: vue composition watch 
Java :: abstract method declaration 
Java :: Number to decimal places in java 
Java :: Error:java: error reading C:UsersMeriem.m2 epositoryorgapachecommonscommons-lang33.12.0commons-lang3-3.12.0.jar; error in opening zip file 
Java :: how to compute age from local date 
Java :: deifine an integer array in java 
Java :: java Math.sqrt(double) 
Java :: interface java 
Java :: potenzieren java 
Java :: convert base64 to pdf object for pdf reader in android studio 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =