6:24 am - Sunday October 22, 2017

This Collection Program is used to get the min elements using min() Method

CANDID INDUSTRIAL TRAINING -- CHENNAI
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

BACK

This Collection Program is used to get the min elements using min() Method

Example Program


import java.util.*;

public class CollectionsDemo {
	public static void main(String args[]) {
		// create link list object
		LinkedList list = new LinkedList();

		// populate the list
		list.add(-18);
		list.add(40);
		list.add(-45);
		list.add(12);

		System.out.println("Min value is: " + Collections.min(list));
	}
}

 

Output:

  • max val :-45

Declaration:

  • public static <T extends Object & Comparable<? super T>> T min(Collection<? extends T> coll)

 

Parameters:

  • coll– The collection whose minimum element is to be determined.

Return Value:

  •     The method call returns the minimum element of the given collection, according to the natural ordering of its elements.

Exception:

  •   ClassCastException–This is thrown if the collection contains elements that are not mutually comparable (for example, strings and integers).

  • NoSuchElementException–This is thrown if the collection is empty.

 

BACK

Filed in: Z-A All Java Codes

Comments are closed.