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 :: how to add elements in array in java using for loop 
Java :: how to hide menu items in android 
Java :: java random unique key 
Java :: set intersection java 
Java :: Fast Lookup of Java 
Java :: generate random color in java in android 
Java :: set visible gui java 
Java :: SendKeys issues with numbers(Int) 
Java :: key listener java 
Java :: selenium java wait for page load 
Java :: circular textview android 
Java :: java delete directory with files 
Java :: convert bytebuffer to string 
Java :: java get file from url 
Java :: initialize arraylist 
Java :: bubble sort for java ArrayList 
Java :: remove fragment from backstack 
Java :: why are there no destructors in java? 
Java :: android studio change menu title 
Java :: permission foreground_service 
Java :: from string to date 
Java :: odd number in java 
Java :: java how to get all threads 
Java :: input array in String in java 
Java :: java insert char in string at index 
Java :: implementing iterator for linked list java 
Java :: Exception in thread main java.lang.RuntimeException: Timeout of 120000 reached waiting for exclusive access to file 
Java :: str.substring last 2 java 
Java :: get year month day from date string java 
Java :: how to find numbers of digits in java 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =