How to sort a card

Hi guys,.

I'm doing an exercise. I want to get a TreeMap sorted by key and print. I thought I can only assign an instance of HashMap to TreeMap instance and it will be automatically sorted, but it does not work. This is the code:
public class Main {
    public static void main(String[] args) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("One", "1");
        map.put("Two", "2");
        map.put("Three", "3");
        map.put("Four", "4");
        map.put("Five", "5");
        
        System.out.println(map);

        Map<String, String> treeMap = new TreeMap<String, String>();

        treeMap = map;

        System.out.println(treeMap);
    }
}
And this is the output:
{Five=5, Three=3, One=1, Four=4, Two=2}
{Five=5, Three=3, One=1, Four=4, Two=2}
How can I sort a TreeMap or HasMap object? So far I haven't found Collections.sort (), but it only works for a list.

Thank you

PR.

Published by: Aardenon on February 17, 2011 13:21

Published by: Aardenon on February 17, 2011 13:22

Aardenon wrote:
I thought that he must sort the plan by keys.

Why the hell would you think that? It is an assignment.

What it does is put your variable "treemap" to point to the table of hash that you just created. Therefore, what you do with it later will work with a hash table.

Winston

Tags: Java

Similar Questions

  • How you sort the list of the next iOS 10?

    I can't know how to sort the list by following in-app music on my iPhone 6 s.  In iOS 9, he had a handle on the right side next to the title of the song that you can tap and drag up/down to change the order of the playlist.  The handle does not appear in the App on iOS 10 music.

    So I guess you can't have activated repeat function.  Once it is off, the handles appear and you can sort your list of songs until the next.

  • My ipod video 5th generation won't play of smart playlists in order with 12.4 itunes, itunes can not remember how to sort things either. When you going to solve the problem?

    My iPod video 5th generation won't play of smart playlists in order with 12.4 iTunes, iTunes can not remember how to sort things either.

    When you going to solve the problem?

    Can I do to solve this problem?

    Use the view of songs to set the order you want. Right-click on the name of the playlist in the left sidebar, and then select copy to Play Order in the context menu. Sort the list on the left most column of numbers, or use view > sort by > order of Playlist. Device synchronization.

    TT2

  • Anyone know how to sort the files in windows 7.

    Anyone know how to sort the files in windows 7. All of a sudden my file says "a long..., there is this month...» Last week... today. I can't deal with all the files in the folder now. How can I keep rid of one a long time ago..., this month... Last week... today) so that I can fix the whole folder?

    Hello

    Right-click on an empty area of the concerned window, select Group By, and then select None.

    Best wishes

    DP - K

  • I want to know how to move the cards while trying to play stings on pogo

    Original title:

    Pogo games

    Hello, it was a gift of birthday a week ago.   So, I'm new on a laptop that I think I'm from fresh all over again.   But here's my question: I want to know how to move the cards trying to play spades on pogo.  Don't know how to slide or push enter or even pushing the button on the finger.  Please help I really like playing Spades and pinochle.  Thank you

    You should ask in the forum games Pogo, not Microsoft.

    http://Games-Forum.Pogo.com/

  • How to synchronize two cards NI9215 DAQmx?

    Hello

    I use two NI9215 DAQmx cards (analog inputs sample simultaneous 4ch) in a cDAQ-9174 chassis type.

    Because I need to acquire 8 channels at the same time, I have two NI9215 cards.

    My question is how to configure these cards to be synchronized?

    I use LabVIEW2009 SP1 dev Suite.

    Thanks for the replies!

    One of the nice things about CompactDAQ is that you can put multiple modules of the same time (analog, digital, etc.) in the same spot and they are automatically synchronized.  Then, to synchronize the two modules, create an analog input task and reference strings like "cDAQ1Mod1 / ai0:3, cDAQ1Mod2 / ai0:3.  It automatically synchronizes the two modules together.

  • How can I insert card

    I got a USB adapter with my 64 GB card Scandisk. I can not understand how to insert the card in there...

    Hogwash. It is provided with the card by ScanDIsk. I found the answer, in any case - you insert the card in the back, above the USB connectir.

  • How to sort the files transferred to the computer

    * Original title: file transfer

    I have files that have names dates in them viz ' 1986 April 1986 may "etc and I have 3000 on my computer in order of date name but when I copy the file to transfer files on an another compluter resort themselves to Aprils all together can all June etc.  Is there a way I can copy the files, but keep them in the same order?

    Hi Anthony,.

    I will definitely help you with this.

    I suggest you to refer to the advice given by Divya R 19 January 2011 and check if it helps.

    http://answers.Microsoft.com/en-us/Windows/Forum/windows_vista-files/how-to-sorting-and-grouping-files-in-Windows/2f2e08c0-587c-47b1-94a1-1779a91090f7

    If the problem persists or you have any other questions, do not hesitate to let us know. It is our pleasure to be of service.

    Thank you.

  • How to sort and organize the desktop icons in Windows Vista?

    How do sort you the icons on the desktop by name or lock the desktop under Vista icons

    Right-click on the desktop and click view.
    To get the icons to stay where it is placed on the desktop.
    Click on align on the grid and automatic uncheck their reorganization.

    To have the icon to align with the grid
    This will keep the icons of overlap between them.
    Click on snap to grid.

    To have the icons align automatically:
    The icons will be automatically aligned in the upper left corner of the office.
    Click Auto arrange.

    Not sure if that's what you are meaning.
    Let us know if that helps.

    Marilyn

  • How to connect a card?

    I have a problem. Anyone know how to link a card instead of a single file in a pdf document. I have Adobe Acrobat Pro XL.

    If you click on an object I want to make a link to a map in the mapstructure.

    Do you mean the link to a folder? If so, it is not possible to implement using Acrobat only.

  • How to create a card for After Effects?

    How to create a card for After Effects?

    After effects Developer Center

  • What is Tri merger and what the syntax or how to sort merge in the optimization of the performance


    Hello

    new IAM for performance how to sort merge and when to do it.

    Thanks in advance.

    Hello

    Merge sort is a method to join two sets of results, which is essentially:

    -First game on the join results sort key

    -Then put spell on the join key

    -Then merge them to produce the output

    Like other methods (hash join, nested... loops joins) the cost of the operation is calculated by the CBO, which chooses the cheaper plan.

    You can force the plan with the use_merge hint... but why would you do?

  • How to sort the videos Sony's AVCHD cam by DATE.

    How to sort the videos Sony's AVCHD cam by DATE.  500 clips in media browser PP are not ordained.  A little more of the FCP where appears the ingestation list, you check what you want and import.  It looks different in PP.  I dragged all the AVCHD folder on the camera (via the copy on the desktop Mac) media victory on PP.  He broke them in 500. Video clips of MTS which cannot be classified by date.  What should do?

    Hi Pup8888,

    pup8888 wrote:

    Here is what I could not say.  He pulls of a Sony 520 in ACVHD and somehow that the data CLEARLY arranged the clips in FCP do not appear in PP.  Maybe it's the issue.

    If you do not ingest the files through their structure to map intact complete with media browser and makes your entire organization in another application, Yes, I can see why some of the metadata is missing.

    pup8888 wrote:

    I also get a DEVICE NOT DETECTED in PP when the camera is clearly working in the new IMAC.

    The remote control is not available for file based devices, so I don't think you need to worry about this.

    pup8888 wrote:

    So I do drag the AVCHD HD folder and import all in PP and yes it in busts. MTS files and works very well but unsortable by date.  They are randomly dumped inn the media browser.  Thoughts?

    Can arrange you by date when they are ingested and in the project Panel? Arrange by date in the media browser would be a feature request. What to do here: http://www.adobe.com/go/wish

    Thank you
    Kevin

  • How to sort bills through customization!

    Dear all,

    Kindly give me some solutions on how to sort bills on date of GL through customization?
    Please reply urgently!

    Kind regards

    Younus

    Hello

    you try like this...

    with the help of the "record tools",
    (1) move the "GL" column in the first position.
    (2) Goto 'File' menu, then select submenu "fate."
    (3) then select Ascending or descending.

    check and update the status

    concerning
    Bassem

  • Verity - how to sort results?

    How a sort a set of data returned by CFSEARCH?
    I'm using CF7.

    Thank you!

    Try the query of queries.

Maybe you are looking for

  • HP Envy 5644: My hp envy 5644 does not install drivers for my laptop

    my HP envy 5644 some drivers will not install and cannot use the eprint button. tried to click on the set up button and accept the terms of use, but he said: "the printer cannot connect to the server...". "I printed the report and the diagnostic resu

  • Recognition of the customer

    Hello I wrote a labview code that sends classify receives and tcp communication and stores these files in the target folder, I did the communication client server. But my server is a loop with a stop button to end the loop. So he will continue to wor

  • new battery but computer still does not load

    I just bought a new battery and the computer will not charge it. It is said to replace the battery.

  • BIOS in an Acer Aspire 8942.

    I'm locked in my BIOS on an ACER Aspire 8942 and I reset the default BIOS and need the factory password to change it as I don't have access. I was doing a refresh and in some way I hit enter and it must have set a password I do not know if it me lock

  • HP laptop - 15-r132wm (ENERG: new laptop turn off - overheat)

    Hello There are two weeks since I bought a new HP laptop, and today it turned randomly off the coast. According to the event viewer on the laptop, it has been overheated. However, how can I directly contact Hp for a repair or a return, because it is