About 2,810,000 results
Open links in new tab
  1. Second Largest Element in an Array - GeeksforGeeks

    Feb 10, 2025 · Given an array of positive integers arr [] of size n, the task is to find second largest distinct element in the array. Note: If the second largest element does not exist, return -1. Examples: Explanation: The largest element of the array is …

  2. Find 2nd Largest Number in an Array in Java - Online Tutorials …

    Learn how to find the 2nd largest number in an array using Java with this comprehensive guide and example code.

  3. Java Program to find Second Largest Number in an Array

    Dec 8, 2024 · We can find the second largest number in an array in java by sorting the array and returning the 2nd largest number. Let's see the full example to find the second largest number in java array.

  4. Java Program to find Second Largest Number in an Array

    In this article, you will see how to find Second largest number in an Array using Java. To understand this program, you should have the basic knowledge of an integer array and the looping concept. Let’s see a few examples here, Example #1. Find the 2nd largest number in the array using java.

  5. java - How do you find second highest number in an integer array ...

    Jan 29, 2014 · int highest = Integer.MIN_VALUE+1; . int sec_highest = Integer.MIN_VALUE; for(int i : b) //b is array of integers. if(i>highest) sec_highest = highest; //make current highest to second highest. highest = i; //make current value to highest. else if(i>sec_highest && i != highest) . sec_highest = i; Another solution is:

  6. Java 8 – Find Second Largest number in an Arrays or List or …

    In this article, we will discuss how to find second largest number in an Arrays and List using Java 8 Stream. Read Java – Find Second Largest number in an Arrays or List ? for finding second largest number without using Java 8 syntax. 1. Finding Second Largest number in an Arrays :

  7. Finding the second highest number in array in Java

    To find the second highest is actually quite simple: static int secondHighest(int... nums) { int high1 = Integer.MIN_VALUE; int high2 = Integer.MIN_VALUE; for (int num : nums) { if (num > high1) { high2 = high1; high1 = num; } else if (num > high2) { high2 = …

  8. Java 8 – How to find the Second Largest Number in an Array?

    Jan 17, 2023 · Find the Second Largest Number in the array using Java 8 Stream. Learn how to do it using two different ways. 1. Skip method 2. Sort and Limit...

  9. Java Program to Find the Second Highest Number in Array

    Mar 27, 2022 · Let’s see step by step approach to find out the second-highest or second maximum number in an array in Java. Find Second Highest/Maximum Number in Array Java. First, we will take the number of elements that the user wants to enter in the array as an input and then initialized an array with that size and take the input from the users.

  10. Method to find second highest number in an array in java

    Jun 19, 2022 · But you can find the second highest number in an array in linear time. Here is one way that doesn't require sorting. now iterate thru the array. else check to see if current value is greater than secondLargest and assign if true. int largest = arr[0]; int secondLargest = Integer.MIN_VALUE; for (int i = 1; i < arr.length; i++) {

  11. Some results have been removed
Refresh