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 / sitaram

package Sample;

import java.util.*;

class Emp
{

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

}

}

class MaxSalaryTest
{

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(2500,"itika"));
a.add(new Emp(90,"latika"));
a.add(new Emp(3200,"jatin"));
a.add(new Emp(340,"nitin"));
a.add(new Emp(2300,"linda"));

Iterator<Emp> i = a.iterator();
int maxsalary=0;
int sal = 0;
while(i.hasNext()){
Emp e = i.next();
sal = e.salary;
if(sal > maxsalary){
maxsalary= sal;
}
}
System.out.println("maximum salary..."+maxsalary);
}

}

Is This Answer Correct ?    15 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Name and explain the types of ways which are used to pass arguments in any function in java.

1024


What is the size of arraylist in java?

992


What is the console in java?

1099


What type of variable is error flag?

1027


How are destructors defined in java?

995


What are the basic interfaces of java collections framework?

1058


What is the maximum size of byte array in java?

969


How big is a gigabyte?

1000


Give reasons supporting that string is immutable.

896


What is difference between jdk,jre and jvm?

1058


What is the byte range?

987


How can you handle java exceptions?

975


Explain the meaning of java applet.

1027


How can we make string upper case or lower case?

1034


What is the difference between an array and an array list?

971