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 8381705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:45:08+00:00 2026-06-09T16:45:08+00:00

Arent Lists a Ordered Collection, and Sets arent ordered? Then Why does this program

  • 0

Arent Lists a Ordered Collection, and Sets arent ordered? Then Why does this program sorts the String in Alphabetical order with Sets but not Lists? I understand the duplicates parts of the two.

    PrintStream out = System.out;

    List<String> set = new ArrayList<String>();
    String s = "ILLUSIONS";

    for(int i = 0; i< s.length(); i++)
    {
        set.add((new Character(s.charAt(i))).toString());

    }
    out.println(set);

outputs: ILLUSIONS


    PrintStream out = System.out;

    Set<String> set = new TreeSet<String>();
    String s = "ILLUSIONS";

    for(int i = 0; i< s.length(); i++)
    {
        set.add((new Character(s.charAt(i))).toString());

    }
    out.println(set);

outputs: ILNOSU

  • 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-06-09T16:45:09+00:00Added an answer on June 9, 2026 at 4:45 pm

    Lists are “ordered” by element index. That means they retain the order of insertion of elements. Sets (in general) do not retain such an order. Some exceptions:

    • The TreeSet is a particular Set, that keeps its elements in a naturally “sorted” order.
    • The LinkedHashSet is a particular Set, that does retain the insertion order.

    If you want to “order” your list, you’ll have to do that manually:

    Collections.sort(list);
    

    In fact, by “sorting” a list, you will re-arrange all list element indexes. See the relevant Javadoc on Collections.sort()

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

Sidebar

Related Questions

This seems to be an easy question to ask, but I am not able
According to this: http://code.activestate.com/lists/python-list/413540/ , tokenize.generate_tokens should be used and not tokenize.tokenize . This
If I understand correctly Clojure can return lists (as in other Lisps) but also
I have a text file that lists the name of a track then after
I already asked this here -> Gather Outlook contacts list But the solution using
Is their a way to add all files that arent present with svn example.
Aren't Javascript blocks supposed to execute in the order that they are placed on
Why aren't many commercial, 3D video games (not random open source 2D ones) written
Cascading deletes aren't setup on this particular database. Just wondering if there's a way
I'm trying to sort a list of dates, but I'm struggling with null dates

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.