Can a Collection be traversed in reverse order?

Hi..
I am using a List of Objects to display..
When I click a Link, it has to be displayed in the reverse order..
Is there any way to do this..
Please help me..
Thanks in advance..

here is the code by which you can traverse a List in
reverse order without modifying contents of the list
import java.util.*;
public class ReverseList {
public static void main(String[] args) {
List first = new ArrayList();
first.add("Java");
first.add("Is");
first.add("Easy");
ListIterator iterator = first.listIterator();
//now traverse a list in forward direction so that
you can reach at the end of the list
while(iterator.hasNext()) {
iterator.next();
//now traverse a list in reverse direction
while(iterator.hasPrevious()) {
System.out.println(iterator.previous());
For a random access list, such as ArrayList, the above is very inefficient. Instead try:
List<String> l = new ArrayList<String>();
l.add( "Java" );
l.add( "Is" );
l.add( "Easy" );
// Jump straight to the end
ListIterator<String> iterator = l.listIterator( list.size() );
// Start iterating
while( iterator.hasPrevious() ) {
    System.out.println( iterator.previous() );
}

Similar Messages

  • Can I chnge the context menu "open in new tab / window" options back to the previous version (reverse order)?

    In Firefox 4, the context menu "open in new tab / open in new window" options are in reverse order compared to 3.6. Can this be "fixed," i.e. change the menu item order? I use this feature constantly and it's a matter of habit, also still use some 3.6 machines.

    You can use the Menu Editor extension to re-arrange the menus - https://addons.mozilla.org/firefox/addon/menu-editor

  • How can i bulk rename music files in reverse order from artist - song name to songname - artist

    How can I bulk rename music files in reverse order from artist - song name to songname - artist.
    I actually dont need to rename the actual files.
    Its just i have a huge txt list of 100,000 music names that are listed as so..
    Artist - Song Name
    Artist - Song Name
    Artist - Song Name
    Artist - Song Name
    Artist - Song Name
    Artist - Song Name
    and i need this list to reverse it self so it is listed in the list as
    Song Name - Artist
    Song Name - Artist
    Song Name - Artist
    Song Name - Artist
    Song Name - Artist
    Song Name - Artist
    Song Name - Artist
    Im sure there is some kinda way to auto a mix of applescript/automator/terminal to do something like:  all char before the "-" replace with the chars after the "-".
    Please some one help me if you know how I can pull this off

    How can I bulk rename music files in reverse order from artist - song name to songname - artist.
    I actually dont need to rename the actual files.
    Its just i have a huge txt list of 100,000 music names that are listed as so.
    I wonder if we haven't misunderstood what you were asking for. Could it be that you have not a huge file, but just a huge list of names in many small files. If that's the case, you should rather use the following script instead of the previous one.
    Since this script does not rename the files, make a backup of your files before running it.
    set theFolder to choose folder -- the folder containing your text files
    tell application "Finder"
        set theNames to name of files of theFolder whose name extension is "txt"
    end tell
    set theTextFiles to {}
    set theFolderPath to POSIX path of theFolder
    repeat with thisName in theNames
        copy theFolderPath & thisName to the end of theTextFiles
    end repeat
    repeat with thisFile in theTextFiles
        set F1 to open for access thisFile
        set theText to read F1
        close access F1
        set theParagraphs to paragraphs of theText
        set bigList to (a reference to theParagraphs)
        set theNewParagraphs to {}
        set bigNewList to (a reference to theNewParagraphs)
        repeat with X in bigList
            set P to offset of " - " in X
            if P = 0 then
                set Y to X
            else
                set Y to text (P + 3) through -1 of X & " - " & text 1 through (P - 1) of X
            end if
            copy Y & return to the end of bigNewList
        end repeat
        set theNewText to text 1 through -2 of (bigNewList as text)
        set F2 to open for access thisFile with write permission
        set eof F2 to 0
        write theNewText to F2
        close access F2
    end repeat
    display dialog "Done!" buttons {"OK"} default button 1 with icon 1
    Message was edited by: Pierre L.

  • How can I get iTunes to NOT fill iPod shuffle in reverse order?

    Any ideas?? iTunes loads my iPod shuffle in the reverse order when I drag tracks from my Music Library to my iPod. This is important because I like to listen to audiobooks during my workouts. All I want is to listen to the first track first and not the last track!
    It seems as if the issue arose when I updated to the latest iTunes (7.1.1.5). The previous version worked just fine for me.
    I reloaded a book that I listened to previously. Although it loaded up several weeks ago OK, now it too loads the tracks in the reverse order.
    Thank you in advance for your suggestions!!
      Windows XP Pro  

    After a couple of days, I'm noticing that the repeat(ing) offenders have more than 10 episodes, and seem to keep repeating them every time I sync.
    They only show once in my phone and in the iTunes Podcasts, but through iTunes and looking at what's in my phone is when I see the repeats.
    Even after I've marked a podcast as played, and deleted it from within my phone, as well as telling iTunes to delete the played episodes, it still shows multiples of the played episodes.
    There doesn't seem to be any rhyme or reason to it either. They aren't the newest ones either.

  • How do I get my ipod to play a playlist from reverse order? (Start with recently added song instead of first added)

    How do I get my ipod to play a playlist from reverse order? (Start with recently added song instead of first added)
    So I'm adding new songs to a very old playlist? Is there anyway that when I add them, they automatically go to top of playlist? How about getting one song to the top of a playlist.  That drag to arrange function is very annoying because it is slow and the playlist does not scroll up very well on a PC.

    Make a new playlist by pressing the little plus button at the very lower left corner of iTunes. An new playlist will appear in the Source pane called "untitled playlist". While the name is highlighted, you can change it to whatever you want. Drag all of the tracks from all the albums that comprise a single book to that playlist. Sync that playlist to your iPod.

  • Reverse order in File- Open dialogue

    The file/folder list in the File->Open dialogue window is "stuck" at showing in reverse order. I can right-click in the Open dialogue window and sort ascending, but the next time I open a file it is back to reverse order.
    I have experimented with Explorer's view settings but Reader appears to ignore those. Other applications, for example Word, use Explorer's view settings and behave as I would expect.
    I suspect that someone has inadvertently changed something on this PC. Perhaps there's a keystroke combination that changes the file display order persistently?
    Any ideas, please?
    Adobe Reader version 8.1.2
    XP Pro SP2

    I'm still struggling with this - does anyone know how to change the file sort order in the File->Open dialogue?
    It must be possible to change it because it has somehow been changed to reverse order!

  • How to print a document in reverse order using Java Print API ?

    I need to print a document in reverse order using Java Print API (*Reverse Order Printing*)
    Does Java Print API supports reverse order printing ?
    Thnks.,

    deepak_c3 wrote:
    Thanks for the info.,
    where should the page number n-1-i be returned ?
    Which method implementation of Pageable interface should return the page number ?w.r.t. your first question: don't return that number but return page n-1-i when page i is requested; your document will be printed in reverse order. Your class should implement the entire interface and wrap the original Pageable. (for that number n your class can consult the wrapped interface; read the API for the Pageable interface).
    kind regards,
    Jos

  • Urgent: How to bring the same pricing procedure in reversal order??

    Hi,
    We have recently implementated CIN at our client location. For the orders present in the system before CIN implementation, when we are creating the reversal orders, system is bringing the new pricing procedure with CIN condition types?
    Can we bring the same pricing procedure in the reversal order as in the sales order? 
    Please advise urgently.
    Regards,
    Peeyoosh.

    Dear Peeyoosh
    I am unable to understand from your comments
    "For the orders present in the system before CIN implementation, when we are creating the reversal orders"
    Please let me know how do you reverse a sale order.  To my knowledge, we can reverse delivery and billing but not sale order.  Either we can close the sale order by assigning some reason for rejection or delete the sale order.
    This being the case, please let me know why you are reversing and how you are reversing.  If you want the same pricing procedure for both normal sales and returns, then maintain the same pricing procedure for both document types.
    thanks
    G.  Lakshmipathi

  • How to copy images from another MC in reversed order??

    Hi everyone,
    I'm new to AS3 and have been fighting and searching for a solution to this problem for a week now, and I'm VERY close!
    I crated a MC holding of a series of images (about 50) and I jump around in it using plenty AS3 scripts (most of which I don't fully understand yet, but I'm working on that to! )
    I had to find a way to "rewind" (= play backwards) the MC. Since there is a stop(); command in almost every frame, prevFrame does not work and if I put that in a loop, it goes WAY to fast (but worked).. So I could think of only one way...
    Create a new (reverserd) MC with the same image sequence ald reverse it manually and play that one.
    This all works fine (very proud of it ).
    Now my question:
    To get this to work for multiple image sequences, I have to load all images twice (once in MC_1 and again in MC_2 and select them and reverse them).
    Not a big one, unless you want to create MANY of those SWF's...
    Is it possible to load the 50 images of the first MC in reverse into the second MC dynamically? JUST the images, noting else.
    extra info: the MC_2 is already in the lib(empty) and placed on the stage.
    something like:
    var pointer:Number=1;
    for (var:i:Number=50;i>=0;i--) {
    get MC_1.picure(var);
    put it in MC_2.frame(pointer);
    pointer = pointer + 1;
    All help is welcome and please take into account that I have little experience and copy most of my scripting from people like you
    T.I.A.
    Melluw

    I tried your advice (thanks for that)
    The event I already have is the mouse leave
    I //-d out the part I removed (what did work)
    The code I ended up with is:
    function Start() {
    stage.addEventListener(Event.MOUSE_LEAVE, cursorHide);
    function cursorHide(evt:Event):void {
    var currFrame = MC_1.currentFrame;
    if (CCW == true) {  //it is true in this case
      movStart = (50 - currFrame);
    else {
      movStart = currFrame;
    if (movStart>25) {
      MC_1.prevFrame();
    // removed swapChildren(MC_1, MC_2); // This is the part I removed
    // removed MC_2.gotoAndPlay(movStart);
    else {
      MC_1.gotoAndPlay (movStart);
    And if I leave the stage on the part where movStart is indeed >25
    Nothing happens,
    So I guess this is not what you meant
    Subject: Action Script 3 how to copy images from another MC in reversed order??
    I cannot direct you in the loading of the images approach, it will be too complicated, and will probably not work anyways... when you move away from a frame that has dynamic content, you lose the content.  So basically, there is nothing practical in taking that approach.
    I do niot understand what the problem will be with the enterFrame/prevFrame approach. If everything you can do with the mouse is already used (which I doubt) by the first mc, then there is nothing else you can do with this file.  You probably just need to rethink your control scheme.  You should search Google for "AS3 slideshow tutorial", and to lighten up your design, add "XML" in that search.
    >

  • Can't get albums/songs in correct order!!! (11.1.3)

    I can't get songs and albums to order correctly on my iPod. All but one album has the correct song order on iTunes on my laptop and they are all ordered by artist/year on iTunes, I can't get that ordering method to transfer to the iPod. And on half the albums on the iPod the songs are out of order and/or the albums are out of chronological order.
    So I had been using some outdated version of iTunes on my old computer for some time, and with that version and my 4th gen Nano I was able to get my albums arranged by year like I like them.
    I bought a new computer (old one still works) and had my iPod stolen about the same time so I had a new computer and was forced to resort to a secondhand 3rd gen Nano, using iTunes 11.1.3, completely unfamiliar to me. Some of the stuff I own isn't off iTunes and that's what I'm having the biggest problem with.
    I had the issue of two songs being in the wrong place on one album. The track numbers were appropriate, everything else in the "get info" field was identical to the rest of the album. Frustrated, I once again copied my library from my old computer to my new one. This was a huge mistake.
    In an attempt to get everything back the way it was I started messing with the iPod settings in iTunes, checking boxes like "manually manage songs" without having a clue what they did. I tried "converting higher bit songs to 192kbps" due to this old turd not being able to hold all my music otherwise. This helped none.
    At least half of my albums were now out of chronological order, some of them were split into 2 albums, (one album would claim to only have one song. It had all 12 or so songs from that album but they were out of order.) Some had all the songs in order but were chronologically incorrect. (2002 album appearing before 1997 album) and some (like the one I got off a CD) are impossible to order correctly. I manually filled out every. single. field. in the "properties" section. The track listing still goes like 2,3,4,5,1,10,7,8,9 or something like that. It is just infuriating.
    I have just had it. I've tried everything I can think of, I've scowered the internet and can't find anything helpful.
    I'm at the point right now where I think it would be easier to just buy 50 CDs and use those to listen to in my car rather than have to deal with Satan's idea of user-friendliness. Any help is greatly appreciated, I've just had it.

    Cal Burke wrote:
    This is a programming error, obviously - to me. Is someone addressing that issue? Anybody?
    What behaviour exactly do you consider to be a programming error? If repeatable and clearly not an intended design choice then a bug report might be in order. If it works as designed but you think it should work differently then feedback would be the way to go. Either way nobody is likely to address an issue that isn't brought to their attention.
    I am unable to put the songs of a playlist I created in the order I want. iTunes 11.1.3 has been on my machine since September of last year and this issue began today. I'd lke to believe it's the result of something I have done, but the world is full of things I would like to believe that are not.
    "View Options" was set to 'manual' and songs would snap back when I attempted to move them, so - as that was the only preference I could find that applied - I changed it to "Artist Name" and back to manual. Now they don't budge when I attempt to move them.
    Ah, when viewing a playlist use the List view and select the heading of the left-most column of numbers. This is the Play Order column. You can drag tracks up and down the list. If you sort on some other column and would like to use this as an initial order which you can then modify, right-click on the playlist name and click Copy to Play Order then select the play order column. Note the triangle should be pointing upwards otherwise the list will play in reverse on your device.
    tt2
    Message was edited by: turingtest2

  • Commands to Print Word Document in Reverse Order and Only Evens or Odds

    I have an HP Photosmart printer that doesn’t have automatic duplex printing, so instead of manually printing the odds and then flipping the paper and printing the evens, I decided to write a script (I’m very new to script writing, so go easy on me):
    tell application "Microsoft Word"
    print out active document print out page type print odd pages only
    end tell
    display dialog "After the papers finish printing and after you place the papers back into the printer, rotated 180º, click OK." buttons {"OK"} ¬
    default button "OK" with icon note
    set the user_choice to the button returned of the result
    if the user_choice is "OK" then
    tell application "Microsoft Word"
    print out active document print out page type print even pages only
    end tell
    end if
    The only things that are working are the printing and the dialog box. The odd pages and even pages scripts don’t seem to work (though I read this passage from Guy Hart-Davis’s +AppleScript: A Beginner’s Guide+ http://books.google.com/books?id=9uBeokAwNLsC&lpg=PA303&ots=ICfmxTfG-W&dq=apple% 20script%20print%20odd%20number%20pages&pg=PA303#v=onepage&q&f=false) and I can’t find any command that will print my even pages in a reverse order. Any help would be so much appreciated.
    Message was edited by: mattshank

    I believe I got the script to print the second round in reverse order, but I still can’t get it to print odd pages only and even pages only.
    tell application "Microsoft Word"
    print out active document
    end tell
    display dialog "After the papers finish printing and after you place the papers back into the printer, rotated 180º, click OK." buttons {"OK"} ¬
    default button "OK" with icon note
    set the user_choice to the button returned of the result
    if the user_choice is "OK" then
    tell application "Microsoft Word"
    print with properties {print reverse}
    end tell
    end if

  • For Each loop that iterates in reverse order

    Can I use the For Each loop to iterate in reverse order?

    Like this:
    int[] array=new int[10];
    for(int i=array.length-1;i<=0;i--)
         int j=array;

  • Some text in the document is shown in reverse order (arabic or something)

    Here's the link to the document https://onedrive.live.com/view.aspx?resid=D3A41CE2D04354EE!4999&cid=d3a41ce2d04354ee&app=Word&wdo=2
    As you can see Word Online (and also standalone Office 2013) is showing one line (marked yellow) in reverse. This line also selects in reverse order and acts like some arabic or other RTL language. Though all text is in Lithuanian. Our employees have to
    work with this document (it's a standard form) all the time. It shows fine with Office 2007, but as we have upgraded to 2013 it now shows like that and every time managers has to deal with this (copying to Outlook or other program where it copies normally
    from left to right, and then back to this document). I wasn't able to find a setting to fix this text.

    Yes, you can update directly using SAVE_TEXT.
    Check this for the same.
    [update long text in FB02|https://forums.sdn.sap.com/click.jspa?searchID=22194840&messageID=5418662]

  • Printing config sm to be set to print in reverse order. How to fix?

    OSX 10.6.3 and MS Word 12.23. When I go to print-to-disk a Word document (i.e. turn it into a PDF using Preview as the default display tool) I get a PDF whose pages are in reverse order. Fine for hard copy output, useless for PDF. Every Print pref or config setting I look for offers no help and, of course, as is completely normal, the Help menu offers nothing either.
    I have found an easy fix for a small document — do a "preview" of the document in the Print dialog then drag the pages manually to where they should be. But not every document I work with is small.
    Suggestions please.

    Oh John, thanks for trying to help. However, I'm not trying to print to any printer. I'm trying to "print-to-disk" i.e. save as a PDF to the desktop so I can later send it as an email attachment.
    And by the way, I forgot to mention for you and other kind folk in here — the Word print dialog box does contain a setting Copies & Pages/Page Handling/Page Order with the options "automatic, normal, reverse" but it makes no difference what I select, I still end up with "reverse".
    Grrr

  • Playlists are all in reverse order

    i've got a 32gb touch, 2nd gen, running xp, latest itunes... blah blah
    for some odd reason. all my playlists are in the reverse order...is there anything i can do, besides restoring my ipod?

    okay there's some sort of error with handling playlists...if you select songs in itunes, and then select "create new playlist from selection", for some reason it shows up in the reverse order on the ipod...
    sorting won't make a difference.... what i did was manually drag and drop songs to playlists.... restoring the ipod didnt work.... sigh... please iron out these bugs apple!

Maybe you are looking for