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 :: android java turn off night mode 
Java :: what is delegation in java 
Java :: has been compiled by a more recent version of the Java Runtime (class file version 55.0) 
Java :: how to call same activity again in android 
Java :: java use space in enums 
Java :: java csv compare 
Java :: pythagoras method in java 
Java :: android alert change color 
Java :: generic method lambda java 
Java :: find the third largest number in an array 
Java :: kotlin edittext default value 
Java :: spring-boot-maven-plugin not found 
Java :: Java Creating a TreeSet 
Java :: get runtime java 
Java :: java stream 
Java :: command to create a Hashmap in Java 
Java :: android bottomnav fab 
Java :: replace everything before a character in java 
Java :: how to get config values bukkit 
Java :: Java List Remove Elements using remove() method 
Java :: access array elements java 
Java :: java garbage collection 
Java :: java compile 
Java :: compare 2 hashmap 
Java :: the java_home environment variable is not defined correctly on mac 
Java :: void * to int 
Java :: variable might not have been initialized error 
Java :: java thread 
Java :: minecraft addlayer(u) in the type rendererlivingentity<t is not applicable for the arguments 
Java :: java 8 iterating and manipulating list 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =