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...

how to get the max salary and name of employee from
arraylist without using the Comperator or even Comparable
interface?

Answer Posted / amit singh

import java.util.*;
class Emp
{

int salary;
String name;
Emp(int i,String g)
{
this.salary=i;
this.name=g;

}

}




class Manhattan
{

public static void main(String []args)
{
ArrayList<Emp> a = new ArrayList<Emp>();
a.add(new Emp(100,"javed"));
a.add(new Emp(500,"apporva"));
a.add(new Emp(250,"sumit"));
a.add(new Emp(100,"itika"));
a.add(new Emp(90,"latika"));
a.add(new Emp(67,"jatin"));
a.add(new Emp(340,"nitin"));
a.add(new Emp(2300,"linda"));


Iterator<Emp> i = a.iterator();
int maxsalary=0;
String name = null;
if(i.hasNext())
{
Emp e=i.next();
maxsalary=e.salary;
}

Iterator<Emp> i1 = a.iterator();
while(i1.hasNext())
{

Emp e1 = i1.next();
if(maxsalary<=e1.salary)
{
maxsalary=e1.salary;
name=e1.name;
}
//System.out.println(maxsalary);

}

System.out.println("he person name is " + name + " whose
havineg the max salary " + maxsalary);
}




}

Is This Answer Correct ?    19 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

When does an object becomes eligible for garbage collection in java?

1002


What are the main uses of java?

934


Can an interface have a constructor?

895


What environment variables are required to be set on a machine in order to run Java programs?

1107


What is final int?

946


What are disadvantages of java?

955


What is the difference between heap memory and stack memory?

1012


Why spring singleton is not thread safe?

956


Which is the best sorting technique in java?

929


What are the java ide’s?

979


Explain java coding standards for variables ?

1108


What is the difference between assignment and initialization?

993


What is string data type?

906


Difference between static binding and dynamic binding?

1035


Explain static nested classes ?

1041