How to copy value of class to another?

R

Raous

I want to sort an array of classes.

So I need to exchange the value of class in this way:

tmp = a;
a = b;
b = tmp;

However, I know that this is not copying the value of class.

Could anyone tell me how to copy the value of class?
 
K

Knute Johnson

Raous said:
I want to sort an array of classes.

So I need to exchange the value of class in this way:

tmp = a;
a = b;
b = tmp;

However, I know that this is not copying the value of class.

Could anyone tell me how to copy the value of class?

You would have to copy the value of all of the class' fields.

But take a look at Arrays.sort(). With that method you can sort an
array of anything. You will need to look at Comparator too.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,436
Messages
2,571,696
Members
48,796
Latest member
Greg L.
Top