Sorting between multiple arrays.

I thought that I had posted this yesterday; however as I can not find my post...
I need assistance with part of a project where I need to sort between multiple arrays; using one of the columns as the sort criteria. The arrays contain integers, strings, and doubles; however I would like to sort and display the arrays alphabetically using the string column. I was told that a bubble array may work, however as I can not find specific information on the use of a bubble array, I really don't know where to start. The arrays look like the following:
productArray[0] = new Product(1, "binder ", 15, 1.5, 0, 0);
productArray[1] = new Product(2, "marker ", 13, .5, 0, 0);
productArray[2] = new Product(3, "paper ", 24, .95, 0, 0);
productArray[3] = new Product(4, "pen ", 5, .25, 0, 0); \
Any assistance that anyone could provide would be greatly appreciated. I am a newbie when it comes to Java and the course materials are extremely vague.
Dman

Thank you for your assistance.
The site that I found to be most helpful was the http://www.onjava.com/lpt/a/3286 site; however I am still experiencing problems. I have added code to the program as noted below:
public class Inventoryprogrampart3
/** Creates a new instance of Main */
* @param args the command line arguments
public static void main(String[] args)
// create Scanner to obtain input from command window
java.util.Scanner input = new java.util.Scanner( System.in );
double totalInventoryValue = 0;
NumberFormat nf = NumberFormat.getCurrencyInstance();
System.out.println(); // Displays a blank line
System.out.println( " Welcome to the Inventory Program - Part 2 " ); // Display the string
System.out.println( " ----------------------------------------- " ); // displays a line of characters
System.out.println(); // Displays a blank line
System.out.println( "This program will output an office supply inventory" ); // Display the string
System.out.println( "listing that includes item numbers for the" ); // Display the string.
System.out.println( "inventoried products, the items product names, the" ); // Display the string.
System.out.println( "quantity of each product in stock, the unit price" ); // Display the string
System.out.println( "for each product, the total value of each products" ); // Display the string
System.out.println( "inventory, and a total value of the entire inventory." ); // Display the string
System.out.println(); // Displays a blank line
System.out.println( "*****************************************************" ); // Displays a line of characters
System.out.println(); // Displays a blank line
Product[] productArray = new Product[ 7 ]; // creates 7 product arrays
// adds data to the 7 arrays
productArray[0] = new Product();
productArray[0].setitemNumber(1);
productArray[0].setproductName ( "binder" );
productArray[0].setitemQuantity(15);
productArray[0].setitemPrice(1.5);
productArray[0].setinventoryValue(0);
productArray[1] = new Product();
productArray[1].setitemNumber(2);
productArray[1].setproductName( "paper" );
productArray[1].setitemQuantity(24);
productArray[1].setitemPrice(.95);
productArray[1].setinventoryValue(0);
productArray[2] = new Product();
productArray[2].setitemNumber(4);
productArray[2].setproductName( "pen" );
productArray[2].setitemQuantity(5);
productArray[2].setitemPrice(.25);
productArray[2].setinventoryValue(0);
productArray[3] = new Product();
productArray[3].setitemNumber(3);
productArray[3].setproductName( "marker" );
productArray[3].setitemQuantity(13);
productArray[3].setitemPrice(.5);
productArray[3].setinventoryValue(0);
productArray[4] = new Product();
productArray[4].setitemNumber(5);
productArray[4].setproductName( "pencil" );
productArray[4].setitemQuantity(28);
productArray[4].setitemPrice(.4);
productArray[4].setinventoryValue(0);
productArray[5] = new Product();
productArray[5].setitemNumber(7);
productArray[5].setproductName( "tape" );
productArray[5].setitemQuantity(14);
productArray[5].setitemPrice(1.65);
productArray[5].setinventoryValue(0);
productArray[6] = new Product();
productArray[6].setitemNumber(6);
productArray[6].setproductName( "staples" );
productArray[6].setitemQuantity(13);
productArray[6].setitemPrice(1.25);
productArray[6].setinventoryValue(0);
System.out.println( "Inventory listing prior to sorting by product name:" );
System.out.println(); // Displays a blank line
System.out.println( "Item #"+"\t"+"Product Name"+"\t"+"Stock"+"\t"+"Price"+"\t"+"Total Value"); // Displays a header line for the inventory array display
System.out.println(); // Displays a blank line
System.out.println( "-----------------------------------------------------" ); // Displays a line of characters
System.out.println(); // Displays a blank line
for (int i=0; i<=6; i++)
Product products = productArray;
String productName = products.getproductName();
int itemNumber = products.getitemNumber();
int itemQuantity = products.getitemQuantity();
double itemPrice = products.getitemPrice();
double inventoryValue = products.getinventoryValue();
System.out.println( productArray[i].getitemNumber() +"\t"+ productArray[i].getproductName() +"\t"+"\t" + productArray[i].getitemQuantity() +"\t"+ nf.format(productArray[i].getitemPrice()) +"\t"+ nf.format(productArray[i].getinventoryValue()) );
Arrays.sort(productArray);
System.out.println( "-----------------------------------------------------" ); // Displays a line of characters
System.out.println(); // Displays a blank line
System.out.println( "Inventory listing after being sorted by product name:" );
System.out.println(); // Displays a blank line
System.out.println( "Item #"+"\t"+"Product Name"+"\t"+"Stock"+"\t"+"Price"+"\t"+"Total Value"); // Displays a header line for the inventory array display
System.out.println(); // Displays a blank line
System.out.println( "-----------------------------------------------------" ); // Displays a line of characters
for(int i=0; i <= 6; i++)
totalInventoryValue = totalInventoryValue + productArray[i].getinventoryValue(); // calculates the total value of the entire products inventory
System.out.println( productArray[i].getitemNumber() +"\t"+ productArray[i].getproductName() +"\t"+"\t"+ productArray[i].getitemQuantity() +"\t"+ nf.format(productArray[i].getitemPrice()) +"\t"+ nf.format(productArray[i].getinventoryValue()) );
}// end for
System.out.println(); // Displays a blank line
System.out.println( "The total value of the entire inventory is: " + nf.format(totalInventoryValue) ); // Displays the entire inventory value
System.out.println(); // Displays a blank line
System.out.println( "*****************************************************" ); // Displays a line of characters
} // end public static void main
}// end public class Inventoryprogrampart3 main
The following utilities have been set:
import java.io.*;
import java.text.*;
import java.util.Scanner;
import java.util.*;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Comparator;
The program compiles, however when I try to run the program I receive the following error (which outputs about 1/2 way through the program:
Exception in thread "main" java.lang.ClassCastException: Product can not be cast to java language comparable.
(along with a listing of other errors - I can't even get my cut and paste to work on my command prompt window).
I've tried about 50 different iterations and nothing seems to work.

Similar Messages

  • Session between multiple Webservice calls from PI7.0

    Hello XI SDNers,
    I am unable to overcome my Webservice session problem using SOAP (Axis) adapter. My scenario is as follows:
    I am calling a external Webservice deployed in Axis webservice engine from PI7.0, during my first call:  I call synchronous "Login" webservice and I became the response "User is Logged in"
    during my second synchronous call "GetItem", the webservice returns "The user doesn't have valid session". The two synchronous calls are executed from same scenario one after another!
    I lost my session after the "Login". Is there any way in PI 7.0 to maintain the session?
    Note: I tried the same scenario using XML SPY SOAP client, it is working!!!  it is maintaining the session between multiple webservice calls.
    Is there any suggestions to overcome this problem?
    Thanks and regards,
    Satish.

    Hi Satish,
       We are working on the same sort of scenarios, where we have to call more than one webservice in a sequential fashion using the same session id details.
        What we did was we built new xsds adding session details node using the webserive request and response xsds. And we are maintaining a sessions table which contains session id and  status fields in PI. So we send webservice request with the session id details. We wrote an UDF to get the session details from PI and set the status field as busy so that no other request uses the same session details.
       Webserive response again contains the sessions details which can be used for the next webservice request.
      Finally after all the calls set back the status to Active in PI table.
    Webservice Calls From a User Defined Function
    /people/bhavesh.kantilal/blog/2006/11/20/webservice-calls-from-a-user-defined-function
    Hope this helps.
    Thanks,
    Vijaya.

  • Chat between multiple users using producer/consumer

    Hi All,
    I'm working on a chat application between multiple users using producer/consumer in flex(pure flex). But i found that this was basically a broadcast service. How do i make sure that i maintain a private chat between any two users using producer/consumer scenario?

    hi,below i write a code,bold lines are properties to use.
    //producer component
    <?xml version="1.0"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Script>
    <![CDATA[
    import mx.messaging.*;
    import mx.messaging.messages.*;
    import mx.messaging.events.*;
    private function sendMessage():void {
    var message:AsyncMessage = new AsyncMessage();
    message.headers = new Array();
    message.headers["prop1"] = 5;
    message.body = input.text;
    producer.send(message);
    ]]>
    </mx:Script>
    <mx:Producer id="producer"
    destination="chat"/>
    <mx:TextInput id="userName"/>
    <mx:TextInput id="input"/>
    <mx:Button label="Send"
    click="sendMessage();"/>
    </mx:Application>
    //consumer component
    <?xml version="1.0"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    creationComplete="logon();">
    <mx:Script>
    <![CDATA[
    import mx.messaging.*;
    import mx.messaging.messages.*;
    import mx.messaging.events.*;
    private function logon():void {
    consumer.subscribe();
    private function messageHandler(event:MessageEvent):void {
    ta.text += event.message.body + "\n";
    ]]>
    </mx:Script>
    <mx:Consumer id="consumer"
    destination="chat"
    selector="prop1 > 4"
    message="messageHandler(event);"/>
    <mx:TextArea id="ta" width="100%" height="100%"/>
    </mx:Application>

  • Space between multiple objects

    Is there a way to alter the space between multiple objects without changing the objects themselves? You know, kind of like inflating/deflating a balloon with dots on the surface (yes, the dots would get bigger/smaller, but I think you get the idea). I've tried Transform>Move>Distance, and Effect>Distort & Transform>Transform>Move>Horizontal/Vertical, but both methods just moved all selected objects away from the origin point - no change to the space between objects. any ideas?

    ...you'd think there'd be an easier way...
    Are you talking about objects that already have equal spaces between them? If so, use the Distribute Spacing function in the Align palette. You can specify the desired horizontal/vertical distance between an array of objects.
    JET

  • How do I use the time capsule to share itunes music between multiple apple devices? Also, is it possible to control the music on one device using another, and how do you set this up?

    How do I use the time capsule to share itunes music between multiple apple devices? Also, is it possible to control the music on one device using another, and how do you set this up?

    unless i'm missing something, i think you got mixed up, this is easy google for walk throughs
    i'm assuming this is the new 3tb tc AC or 'tower' shape, if so, its wifi will run circles around your at&t device
    unplug the at&t box for a minute and plug it back in
    factory reset your tc - unplug it, hold down reset and keep holding while you plug it back in - only release reset when amber light flashes in 10-20s
    connect the tc to your at&t box via eth in the wan port, wait 1 minute, open airport utility look in 'other wifi devices' to setup the tc
    create a new wifi network (give it a different name than your at&t one) and put the tc in bridge mode (it may do this automatically for you, but you should double check) under the 'network' tab
    login to your at&t router and disable wifi on it
    add new clients to the new wifi network, and point your Macs to the time machine for backups

  • Dynamic Sorting on Multiple filed in Crystal report 2008

    Hi
      I am using Crystal report 2008 sp3 full build with hotfix 3.3 along with ASP.NET 2.0
      I have implimented the multi filed sorting using the record sort export and setting the sort order in the report designer.
    Now my requirement is such that i would like to have dynamic sorting on multiple fileds while report is displayed in the UI.
    Means suppose i have a report with Customer region,name,city,rating,status etc.
    Now by using the sort control  i would like to have the functionality in such a way that if user
    a)  first sorts on the region then the records should be first sorted by region
    b)  then sorts on the city then the records should be sorted first by region then by city
    c) now sorts on the  rating then the records should be sorted first by region ,second by city and then by rating
    Now other user may do
    a) first sorts on the rating then the records should be first sorted by rating
    b)  then sorts on the status then the records should be sorted first by rating then by status
    c) now user sorts on the  region then the records should be sorted first by rating,second by status and then by region
    and so on the sorting criteria changes from user to user through the UI.
    Is there any way to achieve the dynamic kind of sorting with Crytsal report 2008 where we can set the order of the fileds at sorting in UI dynamically .The sorting order of the fields are not known at the time of design of the report and its completely depends on the user's need.
    Please let me know if you require any information on the same.
    Regards,
    smitha

    Hello,
       Good Day!
       Thanks for your answer.
       Could you please explain me in detail how to achieve this functionality?
       Do i need to create a static parameter?
       I  get my data set through the command option in crystal report.So i think i need to go by formula in the report.
       i am just putting down the steps to follow.Please correct me if i am wrong.
      step1 :Create s static parameter with the name SORT.
    step2: create the formula as you have mentioned like     
        (IF {?Sort}='Vendor Number' THEN {Pr_Voucher_Status;1.Vendor_Key}& " "& {Pr_Voucher_Status;1.ap_remt_key}
        & " " & {@date}
       else
        IF {?Sort}='Invoice Number' THEN {Pr_Voucher_Status;1.ap_vchr_invno}& " " & {Pr_Voucher_Status;1.Vendor_Key}&
        " " &{@date}
       else
       IF {?Sort}='Invoice Amount' THEN {Pr_Voucher_Status;1.ap_vchr_amtc}& " " & {Pr_Voucher_Status;1.Vendor_Key}&
         " " &{@date})
        I could not  understand what this formula is really doing .
        Could you please tell me what the following names indicates? :
                  Pr_Voucher_Status :- Table/Command name ??
                  Vendor Number,Invoice Number etc.. :-  ??
                 Vendor_Key,ap_vchr_invno,ap_vchr_amtc .. :-  Filed names ??
                 use of 1.{} :- ??                              
    step3: place the below formula in the page header  to display the sort order
        (if {?SORT}='Vendor Number' then "Vendor Number, Remit To, Invoice Date"
              else if {?SORT}='Invoice Number' then "Invoice Number, Vendor Number, Invoice Date"
              else if {?SORT}='Invoice Amount' then "Invoice Amount, Vendor Number, Invoice Date") .
    Note:-My report does not have grouping.Do i need to have grouping?
    in this case how the sort control will work  ?
    As i have mentioned in the first post the order of sorting is completely depends on the user's perspective .
    The report is used by the whole organization ..
    i mean the people with different roles like Manger,Team leads,modul leads,developers ,testers etc..
    the usage of report varies according to the roles so the sort order also.
    Regards,
    smitha.
    Edited by: smitha thomas on Mar 16, 2011 5:01 AM

  • I setup messaging on my verizon, however I have multiple lines on the account and it is showing messaging only for one phone line. Is there a way to toggle between multiple lines on the myverizon site?

    How do I toggle between multiple phone lines while on the myverizon website in regards to messaging?

    The Account Owner can see the call/text logs for all lines on the account, but each line needs its own My Verizon account for messaging and backups.  Those lines will be listed as Account Members and will have limited info. available to them regarding the account.

  • HT1198 If I share an iPhoto library between multiple users, will the Faces, Events, and Places be automatically usable by all users, or will each user have to tag all the photos (e.g. if a user tags a face, will a different user have to do it in their own

    If I share an iPhoto library between multiple users, will the Faces, Events, and Places be automatically usable by all users, or will each user have to tag all the photos (e.g. if a user tags a face, will a different user have to do it in their own iPhoto application??

    Have you read this Apple document regarding sharing a library with multiple users: iPhoto: Sharing libraries among multiple users?
    OT

  • Any improvements in sharing an iPhoto Library between multiple users?

    It is possible and Apple Approved to share an iPhoto Library between multiple users, but the Library must be stored on a drive or disk image that ignores permissions:
    http://tech.kateva.org/2008/10/apple-supports-multi-user-iphoto.html
    This doesn't work for me. Has Apple changed anything with iLife '09 to make it easier to share a Library? For example, have they changed from the prior Package format?
    Message was edited by: jfaughnan

    Alternatives to a trip to the Terminal:
    If you want the other user to be able to see the pics, but not add to, change or alter your library, then enable Sharing in your iPhoto (Preferences -> Sharing), leave iPhoto running and use Fast User Switching to open the other account. In that account, enable 'Look For Shared Libraries'. Your Library will appear in the other source pane.
    Any user can drag a pic from the Shared Library to their own in the iPhoto Window.
    Remember iPhoto must be running in both accounts for this to work.
    If you want the other user to have the same access to the library as you: to be able to add, edit, organise, keyword etc. The problem here is that OS X works very hard to keep your data safe and secure from the other users. You're trying to beat what's built in to the system. So, to beat the system
    Quit iPhoto in both accounts
    Move the iPhoto Library Folder to an external HD set to ignore permissions. You could also use a Disk Image or even partition your Hard Disk.
    In each account in turn: Hold down the option (or alt) key and launch iPhoto. From the resulting dialogue, select 'Choose Library' and navigate to the new library location. From that point on, this will be the default library location. Both accounts will have full access to the library, in fact, both accounts will 'own' it.
    However, there is a catch with this system and it is a significant one. iPhoto is not a multi-user app., it does not have the code to negotiate two users simultaneously writing to the database, and trying will cause db corruption. So only one user at a time, and back up, back up back up.
    Lastly: This method seems a little clunky at first, but works very well. Most importantly, it uses the System to do the job for you.
    Create a new Account on your Mac, call it Media. Create an iPhoto Library there. (BTW: This will work for iTunes too.)
    Enable Sharing on the Library:(Preferences -> Sharing), leave iPhoto running and use Fast User Switching to open the other accounts. In those accounts, enable 'Look For Shared Libraries'. The Library will appear in the other source pane.
    This means that both users will be able to see the pics. If you want to use a pic then simply drag it from the shared Library to your own in the iPhoto Window. This means that each user can have their own edits.
    If you want to add photos to the Library: Log into the Media account for that purpose.
    To make it all seamless: Set your Mac to log into the Media Account automatically. Set iPhoto to launch on log-in. Then switch to your own account using Fast User Switching.
    Net result: a Library that's permanently available to all users but also protected. Each user can have their own versions of the pics if they want.
    No partitioning, no permissions issues. Uses no extra disk space. What's not to like?
    Regards
    TD

  • Question/Problem Sharing iTunes Library between multiple users

    Hello all,
    I have a question (potential problem) regarding sharing an iTunes Library between multiple users.
    In the past, I had placed the iTunes folder in /Users/Shared, and created an alias to it in the "Music" folder of each user, and it worked fine.  However, with a recent upgrade to Mac OS 10.5, only the Home user account can access the library. 
    I read the Apple Support Document http://support.apple.com/kb/ht1203 uner Mac OS X which specifically states *not* to move the iTunes folder, just the iTunes Media folder (which I don't have, would that be iTunes Music?).
    Any recommendations?  Should I delete the different alias, move the iTunes folder back to the home user, and then follow the instructions in the support document?
    We're also looking to sync music purchsed on our iPod touches, as well as apps (which weren't supported in our privous Mac OS X version.
    Any advice is appreiciated.

    David Guay wrote:
    ... iTunes Media folder (which I don't have, would that be iTunes Music?).
    yes.
    specifically states *not* to move the iTunes folder
    *do* keep the entire iTunes folder in /users/shared, however, instead of creating aliases, launch iTunes while holding the option (⌥) key, click choose library when prompted, and select the iTunes folder in /users/shared.
    obviously, only one iTunes at a time can access the library !

  • Using home sharing, can you sync libraries between multiple users in a household?

    Using home sharing, can you sync libraries between multiple users in a household?

    Hey lindsay146,
    Home Sharing lets you to stream or transfer music, movies, and more with up to five authorized computers in your household. You can learn more about it in this link:
    Understanding Home Sharing
    http://support.apple.com/kb/HT3819
    Welcome to Apple Support Communities!
    All the best,
    Delgadoh

  • MobileMe and working on a site between multiple Macs

    In an article I was reading, the following was noted:
    iDisk balks at file packages like iWeb's Domain.sites2 file, making it +difficult for MobileMe users to work on an iWeb site between multiple Macs+.
    Does that mean working at the same time? Or, if for example I'm doing my site on my personal iMac, and then went to college or wanted to work on a MacBook for instance, cannot I complete working on my site through MobileMe?
    I may not be getting it clear.
    Thanks.

    if for example I'm doing my site on my personal iMac, and then went to college or wanted to work on a MacBook for instance, cannot I complete working on my site through MobileMe?
    The point is that to work on an iWeb site with two computers, both must have a copy of the Domain file. There are various ways to do that, like using a memory stick or Dropbox. But uploading and downloading from MobileMe is most likely not practical.

  • Writing multiple arrays to a single xml file at seperate times without overwriting the previous file?

    Hi my name is Dustin,
    I am new to labview and teststand... I am trying to right multiple arrays of data to a single xml file. I can do this with a cluster but I have to create a variable for each of those arrays (21 arrays) and I was hoping to use the same variable for each array. Meaning I obtain my array of data write it to an xml file then replace that array in that variable with a new array and then call up my VI that writes that array to an xml file and write it to the same xml file underneath the first array without overwriting it. Attached is my VI I created to write an array to an xml file. Again I am wondering if there is a way to write multiple arrays to a single xml file at different times without overwriting the previous xml file.
    Thanks
    Solved!
    Go to Solution.
    Attachments:
    Write_to_XML_File.vi ‏11 KB

    Hi dlovell,
    Check the attached example. I think it may help you.
    Regards,
    Nitz
    (Give Kudos to Good Answers, Mark it as a Solution if your problem is Solved) 
    Attachments:
    Write to XML.vi ‏17 KB

  • Obtain Array from an XML file with Multiple Arrays

    Hi,
    So I have been struggling with this program I am making for the last few months but I am almost there. I have a program that creates multiple arrays and place them one after another in an xml file and each array has its own unique name. Now I would like to create a VI that takes this XML file and when the user inputs the specific array name they are looking for it goes into the xml file finds the entire array under that name and displays it in an output indictor to be viewed on the VI. Attached is a sample of my xml file and the VI that creates this xml file.
    Thanks,
    dlovell
    Solved!
    Go to Solution.
    Attachments:
    I_Win.zip ‏20 KB

    Here is a slightly different version. The one above reads from a file. This is how you would read from an already loaded XML string.
    =====================
    LabVIEW 2012
    Attachments:
    Find Array.vi ‏18 KB

  • Newbie trying to sort 2D string array

    Dear all,
    After read some book chapters, web sites including this, I still don't get the point.
    If I have a file like,
    1 aaa 213 0.9
    3 cbb 514 0.1
    2 abc 219 1.3
    9 bbc 417 10.4
    8 dee 887 2.1
    9 bba 111 7.1
    and I load into memory as a String[][]
    here comes the problem, I sort by column 1 (aaa,...,bba) using an adaptation of the Quicksort algorithm for 2D arrays
    * Sort for a 2D String array
    * @param a an String 2D array
    * @param column column to be sort
    public static void sort(String[][] a, int column) throws Exception {
    QuickSort(a, 0, a.length - 1, column);
    /** Sort elements using QuickSort algorithm
    static void QuickSort(String[][] a, int lo0, int hi0, int column) throws Exception {
    int lo = lo0;
    int hi = hi0;
    int mid;
    String mitad;
    if ( hi0 > lo0) {
    /* Arbitrarily establishing partition element as the midpoint of
    * the array.
    mid = ( lo0 + hi0 ) / 2 ;
    mitad = a[mid][column];
    // loop through the array until indices cross
    while( lo <= hi ) {
    /* find the first element that is greater than or equal to
    * the partition element starting from the left Index.
    while( ( lo < hi0 ) && ( a[lo][column].compareTo(mitad)<0))
    ++lo;
    /* find an element that is smaller than or equal to
    * the partition element starting from the right Index.
    while( ( hi > lo0 ) && ( a[hi][column].compareTo(mitad)>0))
    --hi;
    // if the indexes have not crossed, swap
    if( lo <= hi )
    swap(a, lo, hi);
    ++lo;
    --hi;
    /* If the right index has not reached the left side of array
    * must now sort the left partition.
    if( lo0 < hi )
    QuickSort( a, lo0, hi, column );
    /* If the left index has not reached the right side of array
    * must now sort the right partition.
    if( lo < hi0 )
    QuickSort( a, lo, hi0, column );
    * swap 2D String column
    private static void swap(String[][] array, int k1, int k2){
    String[] temp = array[k1];
    array[k1] = array[k2];
    array[k2] = temp;
    ----- end of the code --------
    if I call this from the main module like this
    import MyUtil.*;
    public class kaka
    public static void main(String[] args) throws Exception
    String[][]a = MyUtil.fileToArray("array.txt");
    MyMatrix.printf(a);
    System.out.println("");
    MyMatrix.sort(a,1);
    MyMatrix.printf(a);
    System.out.println("");
    MyMatrix.sort(a,3);
    MyMatrix.printf(a);
    for the first sorting I get
    1 aaa 213 0.9
    2 abc 219 1.3
    9 bba 111 7.1
    9 bbc 417 10.4
    3 cbb 514 0.1
    8 dee 887 2.1
    (lexicographic)
    but for the second one (column 3) I get
    3 cbb 514 0.1
    1 aaa 213 0.9
    2 abc 219 1.3
    9 bbc 417 10.4
    8 dee 887 2.1
    9 bba 111 7.1
    this is not the order I want to apply to this sorting, I would like to create my own one. but or I can't or I don't know how to use a comparator on this case.
    I don't know if I am rediscovering the wheel with my (Sort String[][], but I think that has be an easy way to sort arrays of arrays better than this one.
    I've been trying to understand the Question of the week 106 (http://developer.java.sun.com/developer/qow/archive/106/) that sounds similar, and perfect for my case. But I don't know how to pass my arrays values to the class Fred().
    Any help will be deeply appreciated
    Thanks for your help and your attention
    Pedro

    public class StringArrayComparator implements Comparator {
      int sortColumn = 0;
      public int setSortColumn(c) { sortColumn = c; }
      public int compareTo(Object o1, Object o2) {
        if (o1 == null && o2 == null)
          return 0;
        if (o1 == null)
          return -1;
        if (o2 == null)
          return 1;
        String[] s1 = (String[])o1;
        String[] s2 = (String[])o2;
        // I assume the elements at position sortColumn is
        // not null nor out of bounds.
        return s1[sortColumn].compareTo(s2[sortColumn]);
    // Then you can use this to sort the 2D array:
    Comparator comparator = new StringArrayComparator();
    comparator.setSortColumn(0); // sort by first column
    String[][] array = ...
    Arrays.sort(array, comparator);I haven't tested the code, so there might be some compiler errors, or an error in the logic.

Maybe you are looking for

  • InDesign CS6 "has stopped working" on Windows 7.

    Adobe Community, I just bought a new computer and am in the process of downloading my standard set of programs. I'm testing everything out and InDesign fails to stay open past the new project window. The error just reads the it has stopped working an

  • Drive does not appear in finder

    My Time Machine drive is connected but the drive itself does not appear in the device list in finder. I can set Time Machine preferences in Time Machine software but I cannot access the drive through Finder.

  • Quotation marks removed from XML formatting

    See http://forums.adobe.com/message/4035539#4035539 The original data was <?xml version="1.0" encoding="utf-8" ?> <application xmlns="http://ns.adobe.com/air/application/3.1">     <id>examples.html.HelloWorld</id>     <versionNumber>0.3</versionNumbe

  • Cannot get Satellite L675D to complete restore

    I have been having problems for about 6 weeks with what seemed like a problem of something stepping on something else in memory. I could never find anything in the event log so my assumption has been that the laptop locks before the error can be writ

  • CSACS-3415 ACS 5.4 NIC Bonding / Teaming possible ?

    Hi Team, I know, this topic has been answered for the "old" 11x Appliances: not possible. Does the new UCS hardware change anything ? Can we bundle 2 NICs somehow to get interface redundancy ? If still not possible to configure that in ACS 5 itself: