Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: I want to display the last record first, and the first record last

  1. #1
    Junior Member
    Join Date
    Apr 2020
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I want to display the last record first, and the first record last

    Hello All,
    I have this code pulling data from an SQLite db with multiple columns and records. It works fine, but it displays the record information with the 1st record being displayed 1st. I want to reverse the order so that the LAST record displays first, then the rest with the 1st record being displayed last.... is there an easy way to do this? I've seen several youtube vids but none of them address what i'm trying to do, they just reverse the order of the words, i.e.: Hello becomes olleH. Any help is appreciated. Here is the code i'm using to create the stringbuffer:


    public void viewAll() {
            button_view.setOnClickListener(
                    new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Cursor res = myDb.getLoadData();
                            if(res.getCount() == 0) {
                                // show message
                                showMessage ("Error","No loads found...");
                                return;
                            }
     
                            StringBuffer buffer = new StringBuffer();
                            while (res.moveToNext()) {
                                buffer.append("UNIQUE ID #: " + res.getString(0) + "\n\n");
     
                                buffer.append("LOAD #: " + res.getString(1) + "\n\n");
     
                                buffer.append("PICKUP AT: " + "\n" + res.getString(9) + "\n\n");
                                buffer.append("ON: " + "\n" + res.getString(10) + "\n\n");
     
                                buffer.append("DELIVER TO: " + "\n" + res.getString(14) + "\n\n");
                                buffer.append("ON: " + "\n" + res.getString(15) + "\n\n");
     
                                buffer.append("PAY: " + res.getString(19) + "\n\n");
                                buffer.append("========================"  + "\n\n");
     
                            }
     
                            // Show all data
                            showMessage("LOADS - Basic Info",buffer.toString());
                        }
     
                    }
            );
    Last edited by jgc73; April 2nd, 2020 at 01:54 PM. Reason: part of the code didnt copy/paste

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: I want to display the last record first, and the first record last

    Can you push the records onto a stack and remove them in reverse order?

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2020
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I want to display the last record first, and the first record last

    hmmm, I don't know how to do that. I'm just a beginner in java, and it's only because I've recently gotten interested in it. I'll see if I can find some youtube beginner guides on stacks.... I was just hoping there was an easy way to reverse the order of the records being displayed... Thx for the reply

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: I want to display the last record first, and the first record last

    Look at the ArrayDeque class. It has methods for removing elements from either end of the queue.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Record binary files
    By amit1983 in forum Java Theory & Questions
    Replies: 5
    Last Post: December 22nd, 2013, 04:46 PM
  2. how to record speaker output using cmd
    By shravan in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 5th, 2013, 07:14 AM
  3. The record from database can't be retrieved
    By Asyary92 in forum JDBC & Databases
    Replies: 2
    Last Post: January 10th, 2013, 01:01 AM
  4. How I record sound using MIDI?
    By waseempki in forum Java SE APIs
    Replies: 4
    Last Post: September 16th, 2011, 02:16 PM
  5. Deleting record from database HELP! :(
    By shando1992 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 2nd, 2011, 12:36 AM

Tags for this Thread