Can I sort by the second element in my vector?

The first element is first name and the second is lastname. Right now I am using java.util.Collections.sort(v); This searches on the first name. I would like to search on the last name which is the second element. Any ideas?

Write a subclass of Comparator that looks at the second element, and give an instance of it to the sort method along with the array.

Similar Messages

  • Can I sort on the second element of my vector?

    Sorry to intrude on the guru territory, but no one in the newbie camp has answered and I am sure someone over here has a quick answer...
    The first element is first name and the second is lastname. Right now I am using java.util.Collections.sort(v); This searches on the first name. I would like to search on the last name which is the second element. Any ideas?

    I'm not sure what's in your vector. I assume the vector contains strings, of the form "firstname lastname". In which case I suspect the default implemetation of sort is simply sorting the strings in the natural way. If you look at the second implementation of sort():
    sort(List l, Comparator c)
    you can implement your own comparator. The comparator is an interface tast you implement to compare two object the way you want th sorting done.
    so your comparator would implement compare to find the second word of each string (look at string tokenizer for this) and compare them (with String.compareTo). You need to do something similar with equals.
    So you call sort like this: sort(myVector,new MyComparator());
    Hope this helps.

  • Sort 1D array of clusters by the second element in the cluster

    Hello Folks,
    I need to sort 1D array of clusters [Point (X & Y)] using the second element (Y) of the Point cluster. Can anyone guide!!!!
    Thanks.
    Manu

    I see Darren is a bit faster than me.
    Here's my solution (LabVEWI 7.0), it is pretty similar.
    Message Edited by altenbach on 03-22-200602:01 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    SortByElement2.png ‏4 KB
    SortByElement2.vi ‏27 KB

  • I have 2 Adobe CC subscription plan under same adobe ID, but i only can manage to used on two computers. How can I activate another the second plan.

    I have 2 Adobe CC subscription plan under same adobe ID, but i only can manage to used on two computers. How can I activate another the second plan.

    Hi AndrewHISC
    We would need to cancel one of the subscriptions and then you could sign up again using another ID.
    Let me know if you wish to proceed with this.
    Kind regards
    Bev

  • Can't sort pics the way I want to in Revel.

    I can't sort pics the way I want to in Revel. They're appearing in random format, and I need them displayed in a specific order, like I used to be able to do in photoshop.com.  Is there a way to custom sort pics in Revel??

    At this time, there is not a way to manually arrange your photos from the Revel desktop app. On the iOS, a manual sort is only available in Albums, and not the library.
    Glenyse

  • Where can i download & print the photoshop elements 12 manual

    where can i download & print the photoshop elements 12?

    Moving this discussion to the Photoshop Elements forum.
    JaxsWawa I don't believe there is printable manual available for Photoshop Elements 12.  Instead the help content is primarily available via help files.  The Users in the Photoshop Elements forum though may have additional suggestions on resources which you can obtain.
    There is also several getting started tutorials available at http://helpx.adobe.com/photoshop-elements/topics/getting-started-tutorials.html.

  • How can i sort out the N lowiest elements from an 1D array faster than using the build in sort function (1D-array) in Labview?

    I need an algorithm that is based on the same sorting-algorithm that Labview uses (or one that is just as fast) but it only needs to sort out the N lowiest elements (and the N-element output array don't need to be sorted).
    /Jonas

    I want all three zeros in the output. You can se the algorithm that I'm looking for as a soft version of Labviews own sort algorithm that only gives you the N (always less then the length of the array) lowiest values as output.If two elements contain the same small value both should be sorted out.
    /Jonas

  • How can I remove only the middle elements from a 2-D array?

    Hello all!
    We have had an issue at my work where some of our graphs featuring a Gaussian curve have an unusual rectangular distortion in the middle of the curve (sorry that I have no image to show you, the error is before my time at the company, and I've been asked to find a solution before it happens again). Basically, what should be a Gaussian curve is leveling off briefly and looking like a rounded square wave. We know what causes the distortion, so I only wish to remove the middle part, giving it the appearance of a Gaussian. It's odd, but it actually offers a good approximation of what we want. The graph is made from a 2-D array of Double values, and we can estimate the size of the leveled-area, so I figured that removing the middle elements from the graph would accomplish this. Does anybody know a way I can accomplish this?
    -Gobble
    LabView 8.5.1

    Raven,
    Thank you very much, I'll try that!
    -Gobble
    LabView 8.5.1

  • Itunes can't open right the second time

    So I open my itunes after rebooting and everything is fine. I close it but when I want to re-open it, nothing happens. I have to launch the task manager to stop Itunes working (even if it's not open) and then I open it and it freezes.
    So I got to reboot each time I use Itunes once.
    I reinstall Itunes a lot of times and no changes.
    Maybe I downloaded some program, uninstalled it and then I have this problem with my Itunes.
    What can I do ?

    I installed a product like changing mp3 into another music extension. I uninstalled it and maybee Itunes when into conflict with that so I can't reopen it a second time. Please help!

  • How can I to dissapear the second page when I select a radio buttom YES or NO.

    I want the second page to disappears when I select radio buttom YES or NO.
    If I select YES, the second page continues, but if I press NO, the second page should dissapears, including the footer of the Master Page.
    Please let me know on how to do this, thank you!
    Alexander

    Thank you MTremblay-Savard, I will try to figured out the exact syntax for this one.
    I really appreciated your help!

  • How Come windows 7 can't boot off the second hard drive on MBP?

    i have 2 ssd in my macbook pro. but the second drive (located in the superdrive slot) will not allow windows to boot while the first HDD is in.  When i remove the first HDD, the 2nd hdd boots. this doesnt make and sense as the second bay is still a sata bootable bay as it was the old superdrive slot.  i had switched the hdds too and was able to boot to mac when it was in the second bay.

    Starting up from a system version older than the original one is not supported and usually not possible.

  • I renamed songs in playlist but the original files aren't renamed. How can I sort out the originals?

    I could really use some help. I'm trying to record an audio book of my second novel. I had about 300 audio tracks from recording the book in iTunes. I put them all in a playlist. Then I went through and delected the tracks that were no good from the Playlist and renamed the others so they were properly sorted by page number.
    Unfortunately, I did not realize that 1) renaming tracks in a Playlist does not rename the actual original tracks, and 2) when I click "Show in Windows Explorer" not only is it the original file names, but they are mixed in with all the other tracks that I had deleted from the playlist.
    Is there any way for me to isolate the tracks that are in the Playlist? I need to pull all those tracks out so I can import them into a music editing software program. I'm worried that all my time was wasted renaming the songs and now I can't figure out any way to group those tracks to import into another program.
    Any advice would be much appreciated!
    Thank you.
    - David David Katzman

    When you look at your iPhone, are you looking in the Music app or in the iTunes app?  Be sure you are looking in the Music app, and look in the Songs category.  If your songs are not here, you may want to try syncing your information again through iTunes.  To do this, uncheck "Sync Music" and then click apply or sync in the bottom right corner of iTunes, and then recheck "Sync Music" and then click apply or sync again. 
    I hope this helps!

  • How to get the second element in XML Response with same name

    Hi All,
    I am struck at this point, I have written a sample HTTP client which sends a request to the HTTP Server. In response to the request made the HTTP Server gives response in the XML format. eg: -
    <?xml version="1.0"?>
    <parent>
    <node1> Value1 </node1>
    <node1> Value2 </node1>
    <node2> Value3 </node2>
    </parent>
    In the HTTP Client I am getting the value of node1 using the following statement: -
    if (node instanceof Element && "node1".equals(((Element)node).getName()) )
    String node1 = node.getStringValue();
    System.out.println("Product Code:"+node1);
    This is always returning the first node1 value i.e. <node1> Value1 </node1>.
    The requirement is, I also need to get the <node1> Value2 </node1> value also. So can anyone tell me hw can I get the <node1> Value2 </node1> value. please tell me the piece of code that I should add to get the <node1> Value2 </node1>.
    My Mode is something like this: -
    try
                   Document document = (Document)DocumentHelper.parseText(response);
                   List<Node> transactionNodeList = document.selectNodes( "//parent" );
                   for(Node singleNode:transactionNodeList)
                        for(int i=0,j=0;i< ((Element)singleNode).nodeCount();i++ )
                             Node node = ((Element)singleNode).node(i);
                             if (node instanceof Element && "node1".equals(((Element)node).getName()) )
    node1= node.getStringValue();
    System.out.println("Air Way Bill Number:"+node1);
    if (node instanceof Element && "node1".equals(((Element)node).getName()) )
    node1= node.getStringValue();
    System.out.println("Product Code:"+node1);
    Thanks in Advance

    DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
         DocumentBuilder db=factory.newDocumentBuilder();
         Document doc=db.parse(new File(ur xml file"));
         Element root=doc.getDocumentElement();
         System.out.println("root "+root.getNodeName());

  • How can I sort on the question mark?

    I have catalogue of over 80,000 images and discoverd, this morning, that some are missing. Not merely in the wrong place, but rather, missing from the drive entirely; as if they had been deleted. Fortunately, I found them on a back-up drive. I  copied them back into the principal drive and all is fine with those files. However, I worry that other files, in other folders, may be missing. So I want to search all folders (hundreds of them) in LR 4.4 to find if there are any other images that have the dreaded question mark. Thank you.

    Nonacresu wrote:
    Thanks for your help. I did it in one folder and was rather shocked and baffled by what I found. Actually, two different issues: 
    Be aware that you can't run that command on just one folder....it runs and searches the entire catalog, not just the selected folder.
    First, I found several hundred photos that looked familiar.I compared the file names of them to those in ithe catalogue and note that the filles names are differient. Example: In the catalogue a file is called P1090134_68509.dng whereas Find Missing Photos turned up the same image with the original file name. ie. P1090134.dng. I don't understand how that happened.
    Next, I looked in the directory and found that both images are there! Crazy. Any ideas? I'm not sure what to do next. My intuition tells me to delete all those with the modified file names and re-import those files that have the original file names. What do you recommend?
    I'm not in a position to recommend anything, as I have no idea what you have done to get into that situation. At a minimum it looks as though you have created a differently-named version of a file (which is already cataloged), then perhaps moved them both to a different folder, then imported the differently-named version. Lightroom clearly thinks that the original file is still cataloged, but as you say that it and the other version are together in one folder, I can only think that Lightroom thinks the original file is in a different folder. Suggest you right-click on the "missing" original as select "Go to folder in library" and see what folder is highlighted in the Folders Panel. That may give you a clue as to what you did, and what to do now.
    As to what to do next, well only you know why you have the modified-name duplicates, and thus how important they are to you. Have you done any development work on them, or applied other metadata? You'd lose all that if you delete them and re-import. You might want to consider smply removing the "missing" originals.
    Second, I found several hundred missing files that are just grey. i.e. no thumbnails. I check using Windows Explorer and those images are not physically there at all. Should I just select all those grey "thumbnails" and delete them?
    I appreciate your guidance.
    Again, I can't answer that. You have obviously either deleted or moved those files (maybe even the folders they were in), even before Lightroom had chance to build previews. If you don't know what or where they are now, I guess you have no option other than to remove them.
    But seriously, if you continue to make changes to your image files outside Lightroom, you'll carry on getting this kind of trouble. You can do all these types of changes within Lightroom, which keeps it up-to-date and avoids such problems.

  • I'm new to Itunes and I accidently purchased duplicate audio books .Can I cancle before the second book downloads?

    Is it possible to cancel a duplicate audiobook download ?Didn't realize it wad downloading and reordered same book.

    Same problem.After 30 min figured it out.
    For me:
    hooked up iphone 5 to imac
    Updated ios7
    updated itunes
    downloaded audible.com app and signed in/registered
    went to books tab on iphone while still plugged in
    manual dowload selected audiobooks on syn audiobooks.
    sync and dowload onto iphone
    turned off iphone
    restarted
    audiobooks were under more in music icon on iphone.
    Rather long and silly-but worked.Just had to now redownload all my music as it erased music.
    Seems you can not manually sync music,and audio books-its one or the other.When you click on,the other goes off.Just had to do it sequentially.What made apple a great company seems to be slowly eroding.

Maybe you are looking for

  • Attestation at run time

    Hi All, Can we create the attestation process using API's? We have a requirement that if some event happen, then we can create some attestation process for the users impacting by this event and send this to reviewer. We have to create this attestatio

  • AS01 Asset Master - Custom More Intervals Component

    Hello experts, i need your help to know how to create a custom More Intervals component, is like the same component present in Time-dependent tab, i found the screen in the SAPLAIST program, i add a custom screen in XAIS, and add a push button, so i

  • Updating website from an outside computer

    Is there some way that my website can be updated from an outside computer or from a PC? For instance, if I want to make changes while I am on vacation somewhere, can it be done?

  • Suddenly renames  files edited with external editor

    Not sure what I have done but now when I "edit file with..." (Photoshop CS5) using Aperture3 the version name is changed in Aperture.  Looking in PShop it is dislapying the correct masterfile name but on return to Aperture3 it is changing the version

  • Problem! Flash on Mac

    Hi I'm new to this, I have Flash CS3 on my Mac powerPC G5 OSX 10.4.10 when trying to apply a timeline effect eg a transition, first of all I get a Javascript error msgs (SyntaxError:missing ) after argument list, then TypeError:Object.fxutil has no p