Hiện tại em muốn tìm giá sản phẩm lớn nhất trong một List object của em và sau đó in ra nó. E dùng Collections.max nhưng lại không biết triển khai thế nào cho đúng, e đã tìm mất 1 tgian nhưng chỉ toàn thấy collection.sort . Mong anh chị gợi ý, E cảm ơn
Đây là code của em.
ArrayList<oto> list = new ArrayList<oto>();
public oto b;
public Float gia;
public String nhanhieu;
int n;
public void nhap()
{
Scanner z = new Scanner(System.in);
do
{
System.out.println("Nhao vao so oto");
n =Integer.parseInt(z.nextLine());
if(n<2)
{
System.out.println("Nhap lai");
}
}while(n<2);
for(int i=0; i<n; i++)
{
b = new oto();
System.out.println("nhap vao nhan hieu");
b.nhanhieu = z.nextLine();
System.out.println("Nhap vao gia");
b.gia = Float.parseFloat(z.nextLine());
list.add(b);
}
}
public void max()
{
Collections.max(list, new Comparator<oto>() {
@Override
public int compare(oto o1, oto o2) {
// TODO Auto-generated method stub
return 0;
}
});