java 对象排序快_在java中对对象数组进行排序的最快方法

我有一个名为apple的类,它包含3个值,分别为int x,int y和int weight.然后我创建了一个苹果类型对象的数组.现在我想根据权重对对象数组进行排序,这意味着具有最低权重的苹果对象应该是第一个,依此类推.

我知道有很多方法可以通过使用Arrays.sort等或比较器来实现这一点.

我想知道在Java中这种方法的最快方法是什么?可能有一个案例,我有500,000个对象,所以我想知道我应该使用哪种,更重要的是哪种方法会给我最好的方法.我甚至用Hoare分区编写了自己的快速排序.

Apple类的代码

public class Apple {

public int x;

public int y;

public int weight;

public Apple(int a, int b, int w) {

x = a;

y = b;

weight = w;

}

}

主类代码

public class main {

static Apple[] appleArray;

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int size = sc.nextInt();

int totalApples = sc.nextInt();

appleArray = new Edge[totalApples];

int x = 10;

int y = 20;

int w = 30;

for (int i = 0; i < size; i++) {

appleArray[i] = new Apple(x, y, w);

x++;

y++;

w++;

}

//Now i want to sort array of apple objects based on weight

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值