Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6335943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:57:17+00:00 2026-05-24T18:57:17+00:00

On different sites, i was looking for programme in java doing reversing the order

  • 0

On different sites, i was looking for programme in java doing reversing the order
of linked list(Singly Linked List and and doubly linked list) .I landed up on different sites like

1)http://geek-o-pedia.blogspot.com/2007/07/how-would-you-reverse-singly-linked.html
2)http://stackoverflow.com/questions/354875/reversing-a-linked-list-in-java-recursively

PointA-As per my understanding these programmes(take link 1) are good when you are writing your linked list class as the
programme is assuming we can access Node class which we can not(As its is private inner class in Linked List.)

Point B-Apart from that this programme will permanently reverse the order of Source linked list. So when we iterate on this
we will always get the elemts in reverse order.

Please let me know if both the above points are correct

So i tried to do it myself

–Reversing the singly Linked List

LinkedList list1 = new LinkedList();
    list1.add(1);
    list1.add(2);
    list1.add(3);
    list1.add(4);
    list1.add(5);

LinkedList reverseList1 = new LinkedList();

int size= list1.size();

// below loop will revrse the order of source linked list i.e list1

for(int i =size-1;i>=0;i--)
{
reverseList1.add(size-i-1, list1.get(i));
}

Just wanted to ensure if above approach is correct as i could not find these approach on internet which i found very simple .Everywhere i could find the approach similar to link1 and link2

posted at https://forums.oracle.com/forums/thread.jspa?threadID=2271413&tstart=0 too but did not get proper answer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T18:57:18+00:00Added an answer on May 24, 2026 at 6:57 pm

    This seems like it would work fine. However, there is no need for the 1st parameter for the add method – add already inserts at the end (and you can also use addLast, which is identical).

    Also, using get(i) that many times isn’t efficient. I would iterate over the first list (with foreach or with an iterator – , and for each element call addFirst.

    Alternatively, use Collections.reverse, as panzerschreck suggested, which really is the best way IMO.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

looking at different sites, i see conflicting conventions. if you want to have links
I'm currently looking at the the documentation for Django sites: http://docs.djangoproject.com/en/dev/ref/contrib/sites/#ref-contrib-sites which explains how
I was looking around the web at the way different sites put their favicon
I was looking through different blogs, sites and stack overflow for my answer. I
I'm currently looking at different ways to use various web/internet technologies in order to
I've been looking into different web statistics programs for my site, and one promising
I'm looking into building a content site with possibly thousands of different entries, accessible
I am running two different sites on two different servers with two different domains.
I have several web pages on several different sites that I want to mirror
I'm developing a project with two different sites, divided by language. Maybe I was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.