I think your array should not be simply an array of String
. Inseted you can create an class that contains tow variable name
of type String
and time
of type Integer
. after that you can create an array of objects of the class you created. Then you can sort you list based on the time in second.
the class will be some how like the following: (NOTE: the coded is not tested)
public class SomeClassName
{
private String name;
private Integer time;
// Constructors
public SomeClassName()
{
super();
}
public SomeClassName(String name, Integer time)
{
this.name=name;
this.time=time;
}
// create setter and getter methods
public void setName(String name)
{
this.name=name
}
public void setTime(Integer time)
{
this.time=time
}
public String getName()
{
return name;
}
public Integer getTime()
{
return time;
}
}
then you can create an array of that class as follow:
ArrayList<SomeClassName> list = new ArrayList<SomeClassName>();
list.add( new SomeClassName("PersonOne" ,1234) );
list.add( new SomeClassName("PersonTwo",5678) );
to sort an ArrayList of objects based on some attribute you nee to use custom compactor. check this link: Sort ArrayList of custom Objects by property