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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:24:39+00:00 2026-06-15T01:24:39+00:00

i have a Collection for lastnames read in from an employee class. Is it

  • 0

i have a Collection for lastnames read in from an employee class. Is it possible to Organize the output of the sorted names after the Sort? I need an output that is similar to the line i have commented out, instead of the generic single line output with lastnames seperated by comma “[Name1, Name2, Name3…]” which i get now from the Collection…

 public void alpha1()
    {
     LinkedList<String> alphalist = new LinkedList<String>();
     ListIterator<Employee> iterate = list.listIterator(0);
    // System.out.println("First Name" + "\t" + "Last Name" + "\t" + "Salary");
     while (iterate.hasNext())
      {
           emp = iterate.next();

       alphalist.add(emp.getlastname());
      }
      Collections.sort(alphalist, new Comparator<String>() {
         @Override
         public int compare(String o1, String o2) {
             return Collator.getInstance().compare(o1, o2);
         }
     });
     System.out.println(alphalist);
    }
  • 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-15T01:24:40+00:00Added an answer on June 15, 2026 at 1:24 am

    I think better to create Comparator on Employee object and sort the original collection itself.

    Once your collection is sorted, iterate and print your collection using Employee object itself.

    e.g.

     public void alpha1()
       {
           Collections.sort(list, new Comparator<Employee>() {
            @Override
            public int compare(Employee o1, Employee o2) {
              return o1.getLastName().compareTo(o2.getLastName());
            }
          });
    
          ListIterator<Employee> iterate = list.listIterator();
          while (iterate.hasNext())
          {
            emp = iterate.next();
            System.out.println("First Name" + "\t" + "Last Name" + "\t" + "Salary");
          }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So say I have a collection of Bloops Class Bloop Public FirstName Public LastName
I have Collection List<Car> . How to compare each item from this collection with
I have Class and Student objects. Both have collection of another as property. Which
I have this method that is supposed to search collection of Employees by names.
I have a collection of dictionary values (a List<> ) that I need to
So I have a collection of Razzies created from a Collection of Bloops. I
I've have an Observable collection containing customer objects: public class Customer { public string
I have a large collection of custom objects that I have retrieved from a
I have an employee entity in my EF model. I then added a class
Lets say I have collection of documents with specified longitude and latitude. type is

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.