• Latest Code...

    Featured Post

    Implementing Hilt in a Kotlin Android Jetpack Compose Project with MVVM Architecture

     In modern Android development, maintaining a scalable codebase can be challenging, especially when it comes to dependency management. Hilt,...

    Display Second Largest number in java

    Displaying second largest number in string array in java.

    Here is the full source code, how to display second largest number in integer array ,
    public class One {
    public static void main(String[] args) {

            int arr[] = {5,8,0,7,12};
         
            System.out.println("SortedSet = second largest number is--->"+displaySecond(arr));
           
    }

    private static int displaySecond(int[] arr1) {
    if (arr1.length==0 || arr1.length==1) {
            return -1;
            }else {
            SortedSet<Integer> set = new TreeSet<Integer>();
            for (int i: arr1) {
                set.add(i);
            }
            // Remove the maximum value; print the largest remaining item
            set.remove(set.last());
            return set.last();
    }
    }
    }

    Output looks like:

    SortedSet = second--->8

    Happy Coding!!!


    Contact Form

    Name

    Email *

    Message *