1 Answer(s)      7 years ago
Posted in : Java Interview Questions

program to sort the employees 4 emp salarys...

View Answers

April 1, 2011 at 3:08 PM

import java.util.*;

class ShowData{
        String name;
        String address;
        String email;
        int salary;

        ShowData(String name,String address,String email,int salary){
        public void setName(String name){
                this.name = name;
        public String getName() {
                return name;
         public void setAddress(String address){
                this.address = address;
        public String getAddress() {
                return address;
         public void setEmail(String email){
                this.email = email;
        public String getEmail() {
                return email;
         public void setSalary(int salary){
                this.salary = salary;
        public int getSalary() {
                return salary;
class SalaryComparator implements Comparator{
public int compare(Object emp1, Object emp2){
int salary1 = ((ShowData)emp1).getSalary();        
int salary2 = ((ShowData)emp2).getSalary();
       if(salary1 > salary2)
       return 1;
       else if(salary1 < salary2)
       return -1;
       return 0;    

 public class ArrayListEx{
         public static void main(String[] args){
             Scanner input=new Scanner(System.in);
               ArrayList<ShowData> list=new ArrayList<ShowData>();
               for(int i=0;i<5;i++){
                  System.out.print("Enter name: ");
                  String name=input.next();

                  System.out.print("Enter address: ");
                  String address=input.next();

                  System.out.print("Enter email: ");
                  String email=input.next();

                  System.out.print("Enter salary: ");
                  int salary=input.nextInt();

               list.add(new ShowData(name,address,email,salary));
               System.out.println("Display record with respect to Batting Average: ");
               Collections.sort(list,new SalaryComparator());
                for(ShowData data: list){
                System.out.println(data.getName()+"\t "+data.getAddress()+"\t "+data.getEmail()+"\t "+data.getSalary());


Related Tutorials/Questions & Answers:
j2se  program to sort the employees 4 emp salarys
j2se  program to sort the employees 4 emp salarys
j2se  program to sort the employees 4 emp salarys
j2se  program to sort the employees 4 emp salarys
J2SE  How to encrypt password and retrive orginal password from database i.e decrypted form of password reply as early as possible......... Thanks in advance ravindra   1)form.jsp: <html> <body> <form
j2se - Java Interview Questions
j2se  what is the difference between JVM AND JRE
JTA in J2SE JDB  I am planning to implement a transaction control in J2SE based application with Oracle. JDBC also provides transaction control. I... with simple code example or tuorial about using JTA in j2se perspective
What is J2SE?
What is J2SE?       J2SE is a collection of Java Programming Language API (Application....  J2SE platform has been developed under the Java umbrella and primarily
Difference between Servlet 2.5 and Servlet 2.4
supports for Http, J2SE, and J2EE: Servlet 2.4 depends on Http1.1 and J2SE 1.3....: Dependency on J2SE 5.0: The minimum platform requirement for Servlet2.5
Java 2 Platform-Enterprise Edition
Java 2 Platform-Enterprise Edition       Java Platform, Enterprise Edition builds on the solid foundation of J2SE. It has become an industry standard for developing next-generation web
Beginners Java Tutorials - Installing JDK
download, install and configure the J2SE development environment. Downloading and Installing J2SE Software on Windows Platform To download J2SE for development visit http://www.java.sun.com/j2se and download J2SE on your machine
JavaBeans         JavaBeans are reusable software components designed for the Java 2 Platform, Standard Edition (J2SE). Java Beans are completely written
J2EE Development-zen Platform
development and runtime environment for J2SE and J2EE (Java 2 Platform, Standard
please provide code - Java Beginners
please provide code  provide code to snake game in J2SE
JDBC - Java Beginners
JDBC  How to connect to mysql database from an applets or GUI components (on J2SE) using Eclipse
javabeans - Java Beginners
javabeans  hi sir, Question: what is the compatible J2SE version with bdk1.1(BEAN DEVELOPMENT KIT) . I Have BDK 1.1, to find related J2SE version is problem for me. will u help me in this area of this subject
java - Java Beginners
java  What is the difference between j2se 5.0 and jre? can anyone please tell me about the how to use jre
java standard edition - Java Beginners
java standard edition  good evening sir. i want to install j2se version-6 on my laptop and netbeans, so i want to know the path: and classpath: to type in the environmental variables Dialogue box. also full details about
Java Releases
February 2005 Java 2 Platform, Standard Edition 1.4 (J2SE 1.4... (J2SE 1.3) May 2000 Java 2 Platform, Enterprise Edition... (J2SE) August 1999 Java Development Kit 1.2 (JDK 1.2
JAVA - Java Beginners
edition of Java, JDK 1.4 (or J2SE 1.4), includes new features like a new I/O system... Platform, Standard Edition (J2SE) is an advance version from J2SE 1.3. J2SE 1.4 adds... Edition 5.0 is an advance version of JDK 1.4 (or J2SE 1.4) includes the more
Java for Windows
and Installing J2SE Software on Windows Platform  To download J2SE for windows operating system visit http:/www.java.sun.com/j2se and download J2SE on your... that comes in three editions, J2ME, J2SE and J2EE, if you are learning 
Java installation
java programs. To download J2SE on your machine for development visit http:/www.java.sun.com/j2se. Read more at: http:/www.roseindia.net/java/beginners
file uploading - Java Beginners
file uploading   hi, i am developing one stand alone j2se programming in that i have to upload a file to another system in the LAN and have to download from the server .i am using java.io. and java.net and swing .the task
thanks - Development process
thanks  thanks for sending code for connecting jsp with mysql. I have completed j2se(servlet,jsp and struts). I didn't get job then i have learnt php. Is it right choice. someone say right or someone say wrong. Will u please
java doubt - Java3D
only idea about j2se.... please sugeste me
how to convert jsp to exe
this application in another system. i donot like to install tomcat and j2se
java - Java Interview Questions
and jdk1.5 Sun added some more advanced and some new features to new J2SE 1.5 released as compared to J2SE 1.4. Sun have made more additions to make the Collection
view data from jTextArea to jtable
user friendly. Java consists of Some parts, namely J2SE, J2EE, J2ME.** selection of words: language: java, programming, J2SE, J2EE, J2ME liaison: is, namely
Java Thread Context
the java.lang.Object.  They were introduced in J2SE specifications. This class is essential
Confermation for use of API - Java Beginners
Confermation for use of API  HI ! I am new here. I am making an application for wireless communication between mobile and pc. Let me know which api I have to use at J2SE side. I will be very thankful to you. Regards