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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:00:01+00:00 2026-06-03T04:00:01+00:00

I am implementing a Java class responsible for ordering java.util.List. The problem comes when

  • 0

I am implementing a Java class responsible for ordering java.util.List. The problem comes when I use this class. I’m able to ordering the list but I want to copy the “original” list without modification so that I could register every change made on the original list. The sorted list contains object and one of its fields stores a classification id, and this id it is updated with the index value of the list.

I tried to use clone method and it keeps the list unsorted but the changes made on original list are updated in the clone list too.

Is there any way to accomplish it?

My Code:

List<Torero> listaTorero = tbTlgTorerolHome.findByExample(new Torero());
List<Torero> listaToreroTemp = ((List<Torero>) ((ArrayList<Torero>) listaTorero).clone()); 

Clasificacion clasificacion = new Clasificacion();

Iterator<Torero> iterTorero = clasificacion.getClasificacion(listaTorero, torero).iterator(); //Sorting List

A Clasificacion method:

public List<Torero> getClasificacion(List<Torero> listaToreroTemp, Torero torero)
{

    List<Torero> listaTorero = new ArrayList<Torero>();

    Collections.sort(listaToreroTemp,new ToreroClasifiacionComparator());

    Iterator<Torero> iterTorero = listaToreroTemp.iterator();
    int index=1;
    while(iterTorero.hasNext())
    {
        Torero toreroTemp = iterTorero.next();
        toreroTemp.setNumClasificacion(index);
        listaTorero.add(toreroTemp);
        index=index+1;
    }
    return listaTorero;
}
  • 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-03T04:00:03+00:00Added an answer on June 3, 2026 at 4:00 am

    You may create a new list with an input of a previous list like so:

    List one = new ArrayList()
    //... add data, sort, etc
    List two = new ArrayList(one);
    

    This will allow you to modify the order or what elemtents are contained independent of the first list.

    Keep in mind that the two lists will contain the same objects though, so if you modify an object in List two, the same object will be modified in list one.

    example:

    MyObject value1 = one.get(0);
    MyObject value2 = two.get(0);
    value1 == value2 //true
    value1.setName("hello");
    value2.getName(); //returns "hello"
    

    Edit

    To avoid this you need a deep copy of each element in the list like so:

    List<Torero> one = new ArrayList<Torero>();
    //add elements
    
    List<Torero> two = new Arraylist<Torero>();
    for(Torero t : one){
        Torero copy = deepCopy(t);
        two.add(copy);
    }
    

    with copy like the following:

    public Torero deepCopy(Torero input){
        Torero copy = new Torero();
        copy.setValue(input.getValue());//.. copy primitives, deep copy objects again
    
        return copy;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem implementing this example in java, tableFilterDemo is a class that
I am implementing my own Java class for sorting a List<T> in eclipse. I
I have a Page class implementing java.util.Collection as well as other methods like hasPreviousPage
(Using Java) I am implementing a generic class which is a B-Tree. When the
I have two Java interfaces and one implementing class. (I have used Eclipse to
I am having a really strange problem implementing Java REST service. I am trying
Gwt -> RPC -> MongoDB (Morphia) Caused by: java.lang.IncompatibleClassChangeError: Implementing class at java.lang.ClassLoader.defineClass1(Native Method)
Since I'm using Java 1.4.2, this means that I cannot use Java's implementation of
I'm using an enum singleton, but implementing logging is troublesome. This: public enum Foo
In Java people often define an interface together with a class and use interface

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.