Sorting an array of objects by an attribute

I'm pretty new to java so don't laugh if you think my question is real easy!
I have an array of objects and I want to sort them according to an integer value stored in each object. Any help would be very much appreciated.
Thanks for looking!!

Perhaps an example would help:
public class Person {
  private String name;
  private int age;
  public void setName(String name) { this.name = name; }
  public void setAge(int age) { this.age = age; }
  public String getName() { return name; }
  public int getAge() { return age; }
=====
public class PersonAgeSorter implements Comparable {
  public int compare(Object o1, Object o2) {
    Person p1 = (Person) o1;
    Person p2 = (Person) o2;
    Integer i1 = new Integer(p1.getAge());
    Integer i2 = new Integer(p2.getAge());
    return i1.compareTo(i2);
=====
public class PersonNameSorter implements Comparable {
  public int compare(Object o1, Object o2) {
    Person p1 = (Person) o1;
    Person p2 = (Person) o2;
    String s1 = p1.getName();
    String s2 = p2.getName();
    return s1.compareTo(s2);
=====
import java.util.Arrays;
public class SortExample {
  public static void main(String [] args) {
  Person p1 = new Person();
  Person p2 = new Person();
  p1.setName("Tom");
  p1.setAge(22);
  p2.setName("Nancy");
  p2.setAge(33);
  Person [] people = new Person[2];
  people[0] = p1;
  people[1] = p2;
  Arrays.sort(people, new PersonAgeSorter());
  Arrays.sort(people, new PersonNameSorter());
}

Similar Messages

  • How to sort an array of objects?

    I need to sort an array of objects. Each object has serial number, and other properties. I need to sort it by serial number.

    Do a java.util.Arrays.sort(). The method has quite a few overloads, so I'll give a complete example this time:import java.util.*
    public class SortDemo {
        public static void main(String args) {
            SimpleObject[] objs = new SimpleObject[10];
            for (int i=0; i<10; i++)
                objs=new SimpleObject();
    dump(objs);
    Comparator c = new SimpleComparator();
    Arrays.sort(objs, c);
    dump(objs);
    static void dump(Object[] o) {
    for (int i=0; i<o.length; i++)
    System.out.print(o[i] + " ");
    /** Object to demonstrate comparing with **/
    class SimpleObject {
    private int n = (int) (10*Math.random());
    public String toString() {
    return String.valueOf(getNumber());
    public int getNumber() {return n;}
    /** The custom comparator **/
    class SimpleComparator implements Comparator {
    public int compare(Object o1, Object o2) {
    return ((SimpleObject) o1).getNumber() - ((SimpleObject) o2).getNumber();
    public boolean equals(Object o) {return false;}
    }I could have made the SimpleObject class "Comparable", but a design like this allows more flexibility so I decided to use another class for the Comparator.

  • Sorting an array of objects

    hi there, i have to sort an array of object that looks like:
    surname, name, age, height
    well i have to sort them alphabetically like this:
    based on the surnames, if the surnames are the same than sort on the base of the names; if the names are the same sort them on the base of age and so on. If all the fields are the same the order is non important.
    Well I am not sure how I can do it using the Comparable Interface? as it is an interface i don't have any idea how to implement it

    This search took 2 seconds to do. And it's using your exact subject header. Next time try searching, instead of waiting forever hoping that someone will help you.
    http://search.java.sun.com/search/java/index.jsp?col=javaforums&qp=&qt=%2B%22sorting+an+array+of+objects%22

  • Sorting an array of objects and returning another variable

    Hi there,
    Bit stuck on this one I wonder if anyone can help..
    I have an object array into which I've pushed a number of objects with different variables :-
    myArray.push({myRef: 1, myValue: "W"});
    I can sort the array in numerical order using :-
    myArray.sortOn("myRef", Array.NUMERIC);
    but after sorting I would like to collapse the array using something along the lines of :-
    myArray.join("");
    to join the OTHER variable (myValue)...
    Is it possible to do this without pushing every instance of 'myValue' to another array and then joining that ?
    Many Thanks in advance
    Martin

    Hi kglad,
    I really appreciate you helping, but I have had to completely change my approach to this problem, therefore I will be marking the question as answered !!
    Thanks again

  • Help sorting an array of objects needed please.

    I am trying to sort the array Students[] in descending order of Fees due. Using the code below I get a null pointer error at runtime. The array is not completely full, it has 20 cells, but the variable studentArrayCounter holds the number of used cells. The 'getFeesDue()' code returns an integer value.
    Any help is appreciated.
         // Sort Student Records Method
               public void sortStudentRecords()
                int loopCount = 0;
               for (loopCount = 1; loopCount < studentArrayCounter; loopCount ++)
              if(Students[loopCount].getFeesDue()>Students[loopCount-1].getFeesDue())
                   SortStudents[0]=Students[loopCount-1];
                   Students[loopCount-1]=Students[loopCount];
                   Students[loopCount]=SortStudents[0];
         }

    Also, unless the excersize is to write a sort algorigthm (which I kinda doubt) you should use Arrays.sort
    Arrays.sort(Students, new Comparator() {
      public int compare(Object o1, Object o2) {
        Student s1 = (Student) o1;
        Student s2 = (Student) o2;
        return s1.getFeesDue() - s2.getFeesDue();
    });

  • Java sorting the array of objects

    Hi ,
    I have a question on sorting objects in java.
    I have a java interface some thing like :
    public classmyObj extends Nullable
        private int objId;
        private Datemydate;
        public int getObjID();
        public Date getmyDate();
        public int getISecondD();
      }I need to create the array of the objects of this class that are sorted on the ObjID:
    classmyObj[] collectionObjects
    I need to pass this collectionObjects to another function.
    Now how should I sort these objects based on the ObjID on collection?
    Please help with this!
    Thanks

    neeto wrote:
    Hi ,
    I have a question on sorting objects in java.
    I have a java interface some thing like :You mean class?
    >
    public classmyObj extends Nullable
    private int objId;
    private Datemydate;
    public int getObjID();
    public Date getmyDate();
    public int getISecondD();
    }I need to create the array of the objects of this class that are sorted on the ObjID:
    classmyObj[] collectionObjects
    I need to pass this collectionObjects to another function.
    Now how should I sort these objects based on the ObjID on collection?Create a comparator and use it in a call to Collections.sort (or Arrays.sort if you have an array)

  • Sorting an array of Objects based on a variable inside each object

    I have a class public class handInfo
              //VARS
                   int highC = 0;
                   int hVal = 0;
                   int numHand = 0;
              //CONSTRUCOTRS
                   public handInfo()
              //METHODS
                   public void setHC(int hc)
                             highC = hc;
                   public void setHV(int hv)
                             hVal = hv;
                   public void setNH(int nh)
                             numHand = nh;
                   public int getHC()
                             return highC;
                   public int getHV()
                             return hVal;
                   public int getNH()
                             return numHand;
         }now i have an array, handInfo[] hands = new handInfo[4];
                        hands[0] = new handInfo();
                        hands[0].setHC(HV);
                        hands[0].setNH(1);
                        hands[0].setHV(Val);
                        hands[1] = new handInfo();
                        hands[1].setHC(HV2);
                        hands[1].setNH(2);
                        hands[1].setHV(Val2);
                        hands[2] = new handInfo();
                        hands[2].setHC(HV3);
                        hands[2].setNH(3);
                        hands[2].setHV(Val3);
                        hands[3] = new handInfo();
                        hands[3].setHC(HV4);
                        hands[3].setNH(4);
                        hands[3].setHV(Val4);i need to know how to sort this array, based off hVal...
    D:

    Write a Comparator and call Arrays.sort(array, Comparator).

  • Sorting a vector of objects using attribute of object class as comparator

    i would like to sort a vector of objects using an attribute of object class as comparator. let me explain, i'm not sure to be clear.
    class MyObject{
    String name;
    int value1;
    int value2;
    int value3;
    i've got a Vector made of MyObject objects, and i would sort it, for instance, into ascending numerical order of the value1 attribute. Could someone help me please?
    KINSKI.

    Vector does not implement a sorted collection, so you can't use a Comparator. Why don't you use a TreeSet? Then you couldclass MyObject
      String name;
      int value1;
      int value2;
      int value3;
      // Override equals() in this class to match what our comparator does
      boolean equals (Object cand)
        // Verify comparability; this will also allow subclasses.
        if (cand !instanceof MyObject)
          throw new ClassCastException();
        return value1 = cand.value1;
      // Provide the comparator for this class. Make it static; instance not required
      static Comparator getComparator ()
        // Return this class's comparator
        return new MyClassComparator();
      // Define a comparator for this class
      private static class MyClassComparator implements Comparator
        compare (Object cand1, Object cand2)
          // Verify comparability; this will also allow subclasses.
          if ((cand1 !instanceof MyObject) || (cand2 !instanceof MyObject))
            throw new ClassCastException();
          // Compare. Less-than return -1
          if ((MyObject) cand1.value1 < (MyObject) cand2.value1))
            return -1;
          // Greater-than return 1
          else if ((MyObject) cand1.value1 > (MyObject) cand2.value1))
            return 1;
          // Equal-to return 0.
          else
            return 0;
    }then just pass MyObject.getComparator() (you don't need to create an instance) when you create the TreeSet.

  • How to Sort Array of Object

    Hallo. I have an array of objects. Each object has id and name. How can i sort by name or by id??
    Thx for all
    Max

    array.sortOn("name");

  • Custom Tag using object as an attribute.

    I have read up on trying to pass an object as an attribute to a custom tag.
    Is it true that the only way to do this is to put the object, using a "key name" in the pageContext
    Then in the custom tag, set an attribute equal to the "Key Name"
    Then in the TagHandler, to do a lookup using the "Key Name"
    We can not just past objects into the attribute?
    And what is this about using EL or JSP2.0
    sorry sort of new to the whole game.

    Certainly you can pass objects to tags.
    However you need to use a runtime expression to do that.
    such as <%= expr %> or (with JSP2.0) ${expr}
    If you look at the JSTL library, it uses the EL and passes in objects all the time. However the EL actually accesses the page/request etc attributes as its variable space, so you are still technically using attributes.
    Is it true that the only way to do this is to put the object, using a "key name" in the pageContext
    then in the custom tag, set an attribute equal to the "Key Name"
    then in the TagHandler, to do a lookup using the "Key Name"That is one way of doing it. The struts libraries use this method extensively. It is more suited to JSP1.2.
    Sometimes it is easier/neater just to put the value into a scoped attribute, and pass in the name of that attribute. That way you don't need to worrry about the type of the attribute at all in your JSP.
    Hope this helps some,
    evnafets

  • The CustomDatumExample.java only works if the Employee object has 2 attributes.

    The CustomDatumExample.java only works
    if the Employee object has 2 attributes -
    (EmpName and EmpNo). If I try to add
    another attribute to the Employee object I get java.lang.ArrayIndexOutOfBoundsException: 2 on the getAttr3 method.
    Anyone know why? Thanks.
    Employee object
    CREATE TYPE employee AS OBJECT
    (empname VARCHAR2(50), empno INTEGER,
    attr3 VARCHAR2(50));
    Custom object class
    public class Employee implements CustomDatum, CustomDatumFactory
    public static final String SQLNAME = "EMPLOYEE";
    public static final int SQLTYPECODE = OracleTypes.STRUCT;
    MutableStruct _struct;
    static int[] _sqlType =
    12, 4
    static CustomDatumFactory[] _factory = new CustomDatumFactory[3];
    static final Employee _EmployeeFactory = new Employee();
    public static CustomDatumFactory getFactory()
    return _EmployeeFactory;
    /* constructor */
    public Employee()
    struct = new MutableStruct(new Object[3], sqlType, _factory);
    /* CustomDatum interface */
    public Datum toDatum(OracleConnection c) throws SQLException
    return struct.toDatum(c, SQL_NAME);
    /* CustomDatumFactory interface */
    public CustomDatum create(Datum d, int sqlType) throws SQLException
    if (d == null) return null;
    Employee o = new Employee();
    o._struct = new MutableStruct((STRUCT) d, sqlType, factory);
    return o;
    /* accessor methods */
    public String getEmpname() throws SQLException
    { return (String) _struct.getAttribute(0); }
    public void setEmpname(String empname) throws SQLException
    { _struct.setAttribute(0, empname); }
    public Integer getEmpno() throws SQLException
    { return (Integer) _struct.getAttribute(1); }
    public void setEmpno(Integer empno) throws SQLException
    { _struct.setAttribute(1, empno); }
    public String getAttr3() throws SQLException
    { return (String) _struct.getAttribute(2); }
    public void setAttr3(String attr3) throws SQLException
    { _struct.setAttribute(2, attr3); }
    }

    You also need to add an appropriate element to the _sqlType array.
    In practice, it is easiest to have JPublisher regenerate the CustomDatum class when you have changed your object type definition:
    jpub -user=scott/tiger -sql=EMPLOYEE:Employee

  • Turning a resultset into an array of objects.

    First I will give some background on the situation...
    I have a table in which has many lines of data. Each line of data has a boolean (for a jcheckbox) we will call that "A" and then a bunch of other attributes that are related...we will call those B, C, and D. On a later screen there will be a reduced table in which has only the lines from the original table that were selected. This is why the whole row in the table has to be an object.
    So I have a query like this:
    ResultSet rs = stmt.executeQuery("SELECT A, B, C, D FROM tableName WHERE A= '1'");and then I would like to use:
    String ObjectRef;
                Boolean A;
                String B;
                String C;
                String D;
                while (rs.next()) {
                     A = rs.getString("A");
                     B = rs.getString("B");
                     C = rs.getString("C");
                    D = rs.getString("D");At this point I need to create an ArrayList or an Array of objects....each object having A, B, C, and D. how do I do that in this while condition?
    Or if someone knows a better way of goign about this please let me know. The main objective is to populate this table with objects containing each of of the above attributes. I tried to keep the scenario as simple as possible, so if it was confusing or I need to explain more, just ask.
    Thanks in advance.

    Atreides wrote:
    At this point I need to create an ArrayList or an Array of objects....each object having A, B, C, and D. how do I do that in this while condition?Create the list before you start the while loop. Then, inside the while loop, after extracting A..D, do something like this:
    MyClass mine = new MyClass(A, B, C, D); // or a no-arg c'tor and then a bunch of setters.
    list.add(mine);

  • Passing an array of objects to a method.

    Hi I'm building a program to act as a CD Collection Database. An array of objects represents the entries: Artist, Album and NUmber of Tracks. What I want to do is in the Menu, user to choose wether he or she wants to Add new CD to collection, print or quit, if he/she does then I call a method addNewEntry, to which i pass the array of objects called array, and I want the user to enter the entries each in turn, after that i want the program to return to the method Menu and ask if he or she wants to quit, print or add new cd. The idea is that the details entered already would be contained in the array of objects [0], so the next set of details go to [1] and then to [2] and so on. I have build up the code at this stage but i get an error while copmiling and im totally stuck. Im a beginner in Java.
    Here is the code:
    //by Andrei Souchinski
    //Mini Project: CD Collection Database
    //Designed for a grade F
    //Defining new class of objects to represent CD database entries.
    //A database entry consists of the artist name, the album name and number of tracks.
    //A single entry can be entered by the user typing the details in and the entry can be printed out.
    import javax.swing.*;
    import java.util.*;
    public class MiniProject
         public static void main (String[] args)     
              System.out.println("\tCD Collection Database\n");
              System.out.println("1. Add new Compact Disk to the Database");
              System.out.println("2. Print out current database entries");
              System.out.println("3. Quit\n");          
              theMenu();
         public static void theMenu()
              CompactDisk [] array = new CompactDisk[20];
              String menu;
              menu = JOptionPane.showInputDialog("What would you like to do?");
              if (menu.equals ("3"))
                   JOptionPane.showMessageDialog(null, "Thank You For Using our Service! \nGoodbye!");
                   System.exit(0);     
              if (menu.equals ("2"))
              if (menu.equals ("1"))
              addNewEntry(array);
              else
                   JOptionPane.showMessageDialog(null, "Please select your choice form the menu");
                   theMenu();
         public int addNewEntry(int newcd[])
                   int i;          
                   newcd[i] = (JOptionPane.showInputDialog("Please enter the name of the Artist"));
                   newcd[i] = (JOptionPane.showInputDialog("Please enter the name of the Album"));
                   newcd[i] = (Integer.parseInt (JOptionPane.showInputDialog("Please enter the number of tracks on this album")));
    //A Compact Disk entry consists of three attributes: artist name, album and number of tracks
    class CompactDisk
         public String artistname; //Instance variables for artistname, albumname and numberoftracks.
         public String albumname;
         public int numberoftracks;
         public CompactDisk(String n, String a, int t)
         artistname = n; //Stores the 1st argument passed after "new Dates" into day
         albumname = a; //Stores the 2nd argument passed after "new Dates" into month
         numberoftracks = t; //Stores the 3rd argument passed after "new Dates" into year
         //When called from the main method, prints the contents of
         //artistname, albumname and numberoftracks on to the screen.
         public void printCompactDisk ()
                   String output = "\n " + artistname + "\n " + albumname + "\n " + numberoftracks;
                   System.out.println(output);
    }

    //by Andrei Souchinski
    //Mini Project: CD Collection Database
    //Designed for a grade F
    //Defining new class of objects to represent CD database entries.
    //A database entry consists of the artist name, the album name and number of tracks.
    //A single entry can be entered by the user typing the details in and the entry can be printed out.
    import javax.swing.*;
    import java.util.*;
    public class MiniProject
         public static void main (String[] args)     
              System.out.println("\tCD Collection Database\n");
              System.out.println("1. Add new Compact Disk to the Database");
              System.out.println("2. Print out current database entries");
              System.out.println("3. Quit\n");          
                theMenu();
         public static void theMenu()
              String menu;
              menu = JOptionPane.showInputDialog("What would you like to do?");
              if (menu.equals ("3"))
                   JOptionPane.showMessageDialog(null, "Thank You For Using our Service! \nGoodbye!");
                   System.exit(0);     
              if (menu.equals ("2"))
              if (menu.equals ("1"))
              addNewEntry();
              else
                   JOptionPane.showMessageDialog(null, "Please select your choice form the menu");
                   theMenu();
         public static void addNewEntry()
                   CompactDisk [] array = new CompactDisk[20];
                   int i = 0;
                   array.artistname = (JOptionPane.showInputDialog("Please enter the name of the Artist"));
                   array[i].albumname = (JOptionPane.showInputDialog("Please enter the name of the Album"));
                   array[i].numberoftracks = (Integer.parseInt (JOptionPane.showInputDialog("Please enter the number of tracks on this album")));
    //A Compact Disk entry consists of three attributes: artist name, album and number of tracks
    class CompactDisk
         public String artistname; //Instance variables for artistname, albumname and numberoftracks.
         public String albumname;
         public int numberoftracks;
         public CompactDisk(String n, String a, int t)
         artistname = n; //Stores the 1st argument passed after "new Dates" into day
         albumname = a; //Stores the 2nd argument passed after "new Dates" into month
         numberoftracks = t; //Stores the 3rd argument passed after "new Dates" into year
         //When called from the main method, prints the contents of
         //artistname, albumname and numberoftracks on to the screen.
         public void printCompactDisk ()
                   String output = "\n " + artistname + "\n " + albumname + "\n " + numberoftracks;
                   System.out.println(output);
    I've edited the code, itcompiles, but gives an error when i ran it..:(

  • Creating an array of objects of a class known ONLY at RUNTIME

    I have a method in a class which expects an array of objects of particular type (say A) as its only argument. I 'invoke' this method using reflection. I have the instances of the class A stored in a Vector. When I do 'toArray' on this vector, what I get back is an array of Objects and not an array of objects of A. I assign this array to the zeroth element of another Object array and pass that array as a second argument to the 'invoke' method. Of course, it throws an Exception saying - argument types mismatch. Because I am sending an array of Objects to a method expecting an array of objects of A. My problem is I don't know A until runtime. So I have to handle whatever I am getting back after doing 'toArray' on a vector as a Generic Object. I know there's another version of 'toArray' in the Vector class. But it's API documentation didn't help a lot.
    Can anybody please help me solve this problem? Any sort of hints/code snippet would be of great help.
    Does the above description makes any sense? If not, please let me know. I would try to illustrate it with a code sample.
    Thanks a lot in advance.

    Sorry, for the small typo. It is -
    clazz[] arr = (clazz [])java.lang.reflect.Array.newInstance(clazz, n);
    instead
    Thanks for the reply. I could do this. But I am
    getting a handle to the method to be 'invoke'd by
    looking at the types of the parameters its
    expecting(getParameterTypes). So I can't change it to
    accept an array of Generic Objects.
    I looked at the java.lang.reflect.Array class to do
    this. This is what I am trying to do-
    String variableName is an input coming into my
    program.
    n is the size of the array I'm trying to create.
    Class clazz = Class.forName(variableName);
    clazz[] arr = (clazz
    [])java.lang.reflect.newInstance(clazz, n);
    According to Reflection API, it should work, right?
    But compiler yells at me saying 'class clazz not
    found'.
    Any suggestions/hints/help?
    Thanks, again.

  • Trouble creating and populating an array of objects.

    I'm trying to create/populate an array of objects with consisting of a {string, double, integer}, and am having trouble getting this theory to work in Java. Any assistance provided would be greatly appreciated. Following are the two small progs:
    public class HairSalon
    { private String svcDesc; private double price; private int minutes;
    //Create a constructor to initialize data members
    HairSalon( )
    svcDesc = " "; price = 0.00; minutes = 0;
    //Create a constructor to receive data
         HairSalon(String s, double p, int m)
         svcDesc = s; price = p; minutes = m;
    //Create methods to get the data members
    public String getSvcDesc( )
         return svcDesc;
    public double getPrice( )
         return price;
    public int getMinutes( )
         return minutes;
    public class SortSalon
         public static void main(String[ ] args)
         SortSalon [] sal = new SortSalon[6];
    //Construct 6 SortSalon objects
              for (int i = 0; i < sal.length; i++)
              sal[i] = new SortSalon();
    //Add data to the 6 SortSalon objects
         sal[0] = new SortSalon("Cut"; 10.00, 10);
         sal[1] = new SortSalon("Shampoo", 5.00, 5);           sal[2] = new SortSalon("Sytle", 20.00, 20);
         sal[3] = new SortSalon("Manicure", 15.00, 15);
         sal[4] = new SortSalon("Works", 30.00, 30);
         sal[5] = new SortSalon("Blow Dry", 3.00, 3);
    //Display data for the 6 SortSalon Objects
         for (int i = 0; i < 6 ; i++ )
         { System.out.println(sal[i].getSvcDesc( ) + " " + sal.getPrice( ) + " " + sal[i].getMinutes( ));
         System.out.println("End of Report");

    Hey JavaMan5,
    That did do the trick! Thanks for the assistance. I was able to compile and run the program after adding my sorting routine. Do you happen to see anything I can do to clean it up further, or does it look ok? Thanks again,
    Ironjay69
    public class SortSalon
         public static void main(String[ ] args) throws Exception
         HairSalon [] sal = new HairSalon[6];      
         char selection;
    //Add data to the 6 HairSalon objects
         sal[0] = new HairSalon("Cut", 10.00, 10);
         sal[1] = new HairSalon("Shampoo", 5.00, 11);      
         sal[2] = new HairSalon("Sytle", 20.00, 20);
         sal[3] = new HairSalon("Manicure", 15.00, 25);
         sal[4] = new HairSalon("Works", 30.00, 30);
         sal[5] = new HairSalon("Blow Dry", 3.00, 3);
    System.out.println("How would you like to sort the list?");
         System.out.println("A by Price,");
         System.out.println("B by Time,");
         System.out.println("C by Description.");
         System.out.println("Please enter a code A, B or C, and then hit <enter>");
              selection = (char)System.in.read();
    //Bubble Sort the Array by user selection
              switch(selection)
              case 'A':
              BubbleSortPrice(sal, sal.length);
                   break;
                   case 'a':
              BubbleSortPrice(sal, sal.length);
                   break;
                   case 'B':
              BubbleSortTime(sal, sal.length);                    break;
                   case 'b':
              BubbleSortTime(sal, sal.length);
                   break;
                   case 'C':
              BubbleSortService(sal, sal.length);
                   break;
                   case 'c':
              BubbleSortService(sal, sal.length);
                   break;
                   default:
              System.out.println("Invalid Selection, Randomly Sorted List!");
    //Display data for the 6 HairSalon Objects
              for (int i = 0; i < sal.length ; i++ )
         System.out.println(sal.getSvcDesc( ) + " " + sal[i].getPrice( ) + " " + sal[i].getMinutes( ));
              System.out.println("___________");
              System.out.println("End of Report");
    public static void BubbleSortPrice(HairSalon[] array, int len)
    // Sorts the items in an array into ascending order by price
    int a, b;
    HairSalon temp;
    int highSubscript = len - 1;
    for(a = 0; a < highSubscript; ++a)
         for(b= 0; b < highSubscript; ++b)
         if(array.getPrice() > array[b + 1].getPrice())
              temp = array[b];
              array[b] = array [b + 1];
              array[b + 1] = temp;
    public static void BubbleSortTime(HairSalon[] array, int len)
    // Sorts the items in an array into ascending order by time
         int a, b;
         HairSalon temp;
         int highSubscript = len - 1;
         for(a = 0; a < highSubscript; ++a)
              for(b= 0; b < highSubscript; ++b)
         if(array[b].getMinutes() > array[b + 1].getMinutes())
         temp = array[b];
         array[b] = array [b + 1];
         array[b + 1] = temp;
    public static void BubbleSortService(HairSalon[] array, int len)
    // Sorts the items in an array into ascending order by time
         int a, b;
         HairSalon temp;
         int highSubscript = len - 1;
         for(a = 0; a < highSubscript; ++a)
         for(b= 0; b < highSubscript; ++b)
         if(array[b].getSvcDesc().compareTo( array[b + 1].getSvcDesc()) > 0)
                   temp = array[b];
                   array[b] = array [b + 1];
                   array[b + 1] = temp;

Maybe you are looking for

  • Multiple Sound Clips

    Simple problem, and I hope there's a simple fix . . . I have a sound clip running at the start of a Flash presentation. At some point, I need the first one to stop so I can start the second one. I know there's a difference between "stream" and "event

  • Problems with Flip4Mac WMV and QuickTime 10.1

    I installed Flip4Mac WMV and when I try to listen to some audio in some sites, it starts playing and after about 1 second it starts playing again - so, I have the same thing playing with a delay. I use Mac OS X Lion 10.7.1 and QuickTime 10.1. What is

  • Windows L&F JFileChooser

    My entire application needs to use the Metal L&F except for the JFileChooser. How can I create a JFileChooser using the Windows L&F, while leaving the L&F for the other parts of my app the same?

  • Running Activity Monitor To Shut Unnecessary Functions Off?

    I just ran Activity Monitor to see how the CPU on my MacBook was doing and saw all these "root" functions and this Quicklook thing that list almost 600MB of RAM/Virtual Memory usage. iVirus usage 171MB. Are there ways to disable apps and directory ac

  • Importing CDs larger than 700MB in total size

    When i try to import a CD with a total file size over 700MB the last few songs will not import and the details of the song are in the library but the song cannot be played and the track length is "not available".  Any ideas this is very annoying. I h