Есть такой вот код:
class Type
{
float length;
String name;
public int compareTo(Type tmp) {
return (int) (this.length - tmp.length);
}
}
...
public ArrayList<Type> music;
music = new ArrayList<Type>();
...
Arrays.sort(music);
И выдает ошибки not suitable method found for sort
P.S. не пойму почему одно значение во всех индексах массива:
public void LoadFromFiles()
{
try {
File file = new File("C:\\Users\\User\\source\\repos\\Project1\\Project1\\playlist4.m3u8");
//создаем объект FileReader для объекта File
FileReader fr = new FileReader(file);
//создаем BufferedReader с существующего FileReader для построчного считывания
BufferedReader reader = new BufferedReader(fr);
// считаем сначала первую строку
Type tmp = new Type();
tmp.length = (float) 0.0;
tmp.name = "";
String line = reader.readLine();
while (line != null) {
tmp.name = line;
line = reader.readLine();
tmp.length = Float.parseFloat(line);
music.add(tmp);
//System.out.println(tmp.name+"\n"+tmp.length);
// считываем остальные строки в цикле
line = reader.readLine();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
float length = (float) 3600.0, currentlength = (float) 0.0;
Collections.sort(music);
for(Type t:music)
{
System.out.println(t.name+"\n"+t.length);
}
}