Question Index

Write a program to get the youngest person from the given list of persons.

Input (List) Output (String)
[Amir(1989-06-26), Rohith(1990-06-18), Rajini(1989-01-26), Krishna(1989-08-26)] Rohith
[Lahari(1988-11-21), Jyothi(1988-11-30), Chaitanya(1988-08-20), Pavan(1979-03-18), Akhil(1978-02-27), Sowjanya(1988-10-26)] Jyothi
[Lahari(1988-11-30), Jyothi(1988-11-21), Chaitanya(1988-11-20), Pavan(1988-11-18), Hemanth(1988-11-27), Krishna(1988-11-26)] Lahari
[Lahari(1978-11-30), Jyothi(1988-10-30), Chaitanya(1988-08-20), Pavan(1979-03-18), Akhil(1988-11-30), Sowjanya(1966-09-17)] Akhil

import java.util.*;
import java.text.*;
class GetTheYoungestPerson
    public static void main(String s[])
        ArrayList<Person> list = new ArrayList<Person>();
        list.add(new Person("Amir", new GregorianCalendar(1989, 5, 26)));
        list.add(new Person("Rohith", new GregorianCalendar(1990, 5, 18)));
        list.add(new Person("Rajini", new GregorianCalendar(1989, 0, 26)));
        list.add(new Person("Krishna", new GregorianCalendar(1989, 7, 26)));
        System.out.println("The youngest person is " + getTheYoungestPerson(list));


    public static String getTheYoungestPerson(ArrayList<Person> input) {

class Person {

String name;
Calendar dateOfBirth;

Person(String name, Calendar dateOfBirth) { = name;
this.dateOfBirth = dateOfBirth;



Topic: Java GregorianCalendar

Read this topic
Take test on this topic

Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App