• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to order two ArrayList in one?  RSS feed

 
pac shakur
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi suppose I have an ArrayList of employee and ArrayLsit of bosses, and I want to keep those people in a temporary ArrayList , then ordain alphabetically by name, to sort I use the interface comparator.

The problem comes when I will order 2 ArrayList(workers and bosses), because every time I call I use these functions or not is ordered (sortByNameAlphabetical())

Can anyone help me ?
thanks





 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you trying to combine Employees and Bosses? Are they subclasses of a common superclass? There is something wrong about having different methods depending on what sort of object you are dealing with. The object‑oriented way to do it is to have a superclass with the common behaviour in. I think you will have to redesign your two classes, I am afraid.

And welcome to the Ranch
 
pac shakur
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Why are you trying to combine Employees and Bosses? Are they subclasses of a common superclass? There is something wrong about having different methods depending on what sort of object you are dealing with. The object‑oriented way to do it is to have a superclass with the common behaviour in. I think you will have to redesign your two classes, I am afraid.

And welcome to the Ranch


This was a small example of what I'm doing , partly if , say employees is an abstract class, and workers and bosses, inherited from employees, this code just put it as an example , because I can not show ordered both workers and workers
 
Carey Brown
Saloon Keeper
Posts: 3310
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pac shakur wrote:Hi suppose I have an ArrayList of employee and ArrayLsit of bosses, and I want to keep those people in a temporary ArrayList , then ordain alphabetically by name, to sort I use the interface comparator.

The problem comes when I will order 2 ArrayList(workers and bosses), because every time I call I use these functions or not is ordered (sortByNameAlphabetical())

Can anyone help me ?
thanks

Sorry, but I'm having a difficult time getting past your broken English. You have 3 lists but you are only sorting 1 and the 1 you sort you are not printing out. Can you try again to break out the steps you are taking (or want to take) and what results you are expecting?
 
pac shakur
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 2 main lists
These workers and bosses.

These two lists use them to save them in another temporary arraylist .

With the temporary arraylist , ordered alphabetically .

Finally I show the sorted results.

sorry for my poor English level.
 
Carey Brown
Saloon Keeper
Posts: 3310
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pac shakur wrote:Finally I show the sorted results.

The only place you show the sorted results is in the showEmployesAndBosses() method which is not being called from anywhere. Also, should be showWorkersAndBosses().
 
pac shakur
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you all for the answers, finally , I've gotten sort the problem had it in the constructor.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!