Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java arraylist get second largest value

public class Main {

    public static void main(String[] args) {
        // Find the 2nd largest value in a ArrayList
        ArrayList<Integer> numbers = new ArrayList<>(Arrays.asList(101, 222, 4829, 352, 8238, 2835, 29));
        Collections.sort(numbers);

        int secondLargestNumber = numbers.get(numbers.size() - 2);
        System.out.println(secondLargestNumber);
    }
Comment

PREVIOUS NEXT
Code Example
Java :: primefaces custom validator 
Java :: how to start activity in adapter android 
Java :: java input character 
Java :: containskey java complexity 
Java :: java swing enter key press event 
Java :: inputing number in java 
Java :: java loop backwards through array 
Java :: convert date to calendar java 
Java :: iterator constructor java 
Java :: org.mockito.exceptions.misusing.WrongTypeOfReturnValue 
Java :: install java centos 8 
Java :: java read file bufferedreader 
Java :: is prime java 
Java :: java code to reverse an integer 
Java :: java random seed 
Java :: print line in jjava 
Java :: getsupportactionbar activity 
Java :: static and final in java 
Java :: hashmap sort by value descending 
Java :: jagged array java 
Java :: What is unreachable catch block error? 
Java :: java alert box 
Java :: java outer class 
Java :: {} when initialising arraylist java 
Java :: java infinitew recursion 
Java :: try catch java 
Java :: java long to int 
Java :: turn java code to .exe 
Java :: java guid 
Java :: intent filter 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =