7:55 pm - Tuesday April 23, 2019

Java Program to Find maxmimum element of HashSet

Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

import java.util.HashSet;

import java.util.Collections;

class FindMaximumOfHashSet{

public static void main(String[] args) {

//creating Hashset Object

HashSet hashSet = new HashSet();

hashSet.add(new Long("923740927"));

hashSet.add(new Long("4298748382"));

hashSet.add(new Long("2374324832"));

hashSet.add(new Long("2473483643"));

hashSet.add(new Long("32987432984"));

//using collections.max() method the maximum of element is find

Object obj = Collections.max(hashSet);

System.out.println("Maximum Element of Java HashSet is : " + obj);




D:\CandidJava\Util\HashSet>javac FindMaximumOfHashSet.java

Note: FindMaximumOfHashSet.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

D:\CasndidJava\Util\HashSet>java FindMaximumOfHashSet

Maximum Element of Java HashSet is : 32987432984

Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply