Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  




Share on Google+Share on Google+

patel nikesh
1 Answer(s)      5 years and 6 months ago
Posted in : JavaScript Questions

write a java program to arange 10 employee names in ascending order.

View Answers

December 23, 2011 at 3:17 PM

import java.util.*;

class Employee{
public int salary;
public String name;
public String address;
public static int count = 0;
public Employee(){}
public Employee(String name,String address,int salary) {
super(); = name;
this.salary = salary;

public String getName(){
return name;
public String getAddress() {
return address;
public int getSalary(){
return salary;
class NameComparator implements Comparator{

    public int compare(Object emp1, Object emp2){    

        String emp1Name = ((Employee)emp1).getName();        
        String emp2Name = ((Employee)emp2).getName();
        return emp1Name.compareTo(emp2Name);
public class EmployeeNameInAscendingOrder{
public static void main(String[] args) throws Exception{
List<Employee> list = new ArrayList<Employee>();
list.add(new Employee("Victor","Delhi",10000));
list.add(new Employee("Jennie","Mumbai",20000));
list.add(new Employee("John","Chennai",15000));
list.add(new Employee("Daniel","Kolkata",12000));
list.add(new Employee("Angelina","Pune",16000));
list.add(new Employee("Maria","Hyderabad",22000));
list.add(new Employee("Zenn","Agra",25000));
list.add(new Employee("Andy","Jaipur",22000));
list.add(new Employee("George","Nagpur",25000));
list.add(new Employee("Chris","Darjeeling",22000));

System.out.println(" ");
int count=0;
int salary=0;
               Collections.sort(list,new NameComparator());
                for(Employee data: list){



Related Tutorials/Questions & Answers: