简体   繁体   English

排序2d对象数组Java

[英]Sorting 2d object array Java

I have an object array with customers. 我有一个客户对象阵列。 Every customer has max number of wishes. 每个客户都有最大的愿望。 I have: 我有:

Customer[] customer  = new Customer[numOfCustomers]
C_wishes [][] w = new C_wishes[numOfCustomers] [maxWishes]

I sorted the out the customers with bubble sort but I can't do it the same with 2d array. 我用冒号排序了客户,但我不能用2d数组做同样的事情。 Basically i would like to do something like this 基本上我想做这样的事情

[[obj7,o8, o9],[o1,o2,o3],[o4,o5,o6]] => [[obj1,o2, o3],[o4,o5,o6],[o7,o8,o9]]

but at some point the wishes don't align with customers. 但在某些时候,愿望与客户不一致。 I'll post the code as soon as I can. 我会尽快发布代码。

Id use a HashMap. 我使用HashMap。 Maps and Lists usually have sorting functions built in. 地图和列表通常具有内置的排序功能。

You need to know how to use 1.8 Lambdas tho 你需要知道如何使用1.8 Lambdas tho

(如果你不想使用HashMaps)只需创建一个临时2d数组,根据子数组中的第一个值对每个子数组(意思是排序所有temp[i] )进行排序(意思是基于temp[i][0] )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM