0% found this document useful (0 votes)
8 views2 pages

Generics

The document presents a Java class named 'GENERICS' that includes a generic method 'max' to find the maximum value among a variable number of comparable elements. The main method demonstrates the usage of this 'max' method with different data types such as Integer, String, Double, Boolean, and Byte. The output of the maximum values for each type is printed to the console.

Uploaded by

paulsenthil2005
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Generics

The document presents a Java class named 'GENERICS' that includes a generic method 'max' to find the maximum value among a variable number of comparable elements. The main method demonstrates the usage of this 'max' method with different data types such as Integer, String, Double, Boolean, and Byte. The output of the maximum values for each type is printed to the console.

Uploaded by

paulsenthil2005
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

GENERICS CLASS

package generics;

import [Link].*;

public class GENERICS {

public static <T extends Comparable<T>> T max(T... elements)

T max = elements[0];

for (T element : elements) {

if ([Link](max) > 0)

max = element;

return max;

public static void main(String[] args)

[Link]("Integer Max: " + max([Link](32), [Link](89)));

[Link]("String Max: " + max("GaneshBabu", "Ganesh"));

[Link]("Double Max: " + max([Link](5.6), [Link](2.9)));

[Link]("Boolean Max: " + max([Link], [Link]));

[Link]("Byte Max: " + max(Byte.MIN_VALUE, Byte.MAX_VALUE));

}
GENERICS

You might also like