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 :: sum of array in java 
Java :: Java Abstract Class and Method 
Java :: java spring mvc 
Java :: java interview questions for freshers 
Java :: check if object is empty java 8 
Java :: camunda 
Java :: |= java operation 
Java :: for loop in java 
Java :: Permutations of array in Java 
Java :: java code to get all leaf nodes of a xml 
Java :: calculate the area of two squares in java by using a method 
Java :: why the fuck java suck 
Java :: preset arraylist java 
Java :: Java program to swap two numbers using bitwise xor operator 
Java :: session management in java spring boot for login logut 
Java :: location.href webview android studio 
Java :: key caracter from code java 
Java :: java namespaces 
Java :: zoom sdk not initialized 
Java :: java split not working on comma 
Java :: the crystallization in time is the phenomenon that we call synchronization 
Java :: cgange background from button click java fx 
Java :: how to use asynx task to make api connection java 
Java :: java hashmap get nonexistent key 
Java :: HOW TO CODE WORKING PLUGIN IN MINECRAFT 
Java :: jbutton scroll list full width size 
Java :: java datasource 
Java :: how to avoid outside click of alerdialoge android 
Java :: java lambda expressions qunado foi implantada 
Java :: java clump list 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =