Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

write java code to print second max number in the array

Answer Posted / himesh mistry

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;


public class SecondMax {

/**
* @param args
*/
public static void main(String[] args) {
int[] numbers = {9,4,8,0,0,5,9,1,4,2};
Set arrSet = new HashSet();
for (int i=0;i<numbers.length;i++) {
arrSet.add(numbers[i]);
}
ArrayList s = new ArrayList(arrSet);
Collections.sort(s);

System.out.println("Second element : " +
s.get(s.size()-2));
}
}

Is This Answer Correct ?    16 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is synchronization and why is it important in java programming?

935


Which of the following is not an isolation level in the JDBC

2121


What is externalizable interface?

1094


What are the data types supported by java? What is autoboxing and unboxing?

1015


What are green threads in java?

997


What is the use of default method in interface in java? Explain

996


How to make a class or a bean serializable?

968


How do you add spaces in java?

1000


What is oops in java?

1012


Explain the difference between collection api and stream api in java8?

965


What is executor memory?

939


What is an 8 bit word?

1046


How do I start learning java?

1059


How to connect to a remote database using Applet?

2533


What does += mean coding?

925