I am currently new to this java and I have a question about sorting arrays
. I have this code in a previously created class.
public class Orden {
int value;
public Orden(){}
public Orden(int value){
this.value= value;
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
}
Then I have another class with the following:
public class Main {
public static void main(String[] args) {
int i;
int j;
int aux;
Orden[] cosa=new Orden[10];
cosa[1]= new Orden(5);
cosa[2]= new Orden(9);
cosa[3]= new Orden(55);
cosa[4]= new Orden(88);
cosa[5]= new Orden(44);
cosa[6]= new Orden(66);
cosa[7]= new Orden(33);
cosa[8]= new Orden(33);
cosa[9]= new Orden(44);
cosa[0]= new Orden(88);
for(i=0;i<(cosa.length-1);i++)
{
for(j=i+1;j<cosa.length;j++)
{
if(cosa[i].getValue()>cosa[j].getValue())
{
aux=cosa[i].getValue();
cosa[i]=cosa[j];
cosa[j]=aux;
}
}
}
}
}
But I have an error in the line where cosa[j]=aux;
is indicated. According to what I have been able to understand, it is because I am saving an object in a variable int
, but I can not see how to save that value in the variable aux
. Any recommendation?