Search code examples
javaarrays2dbubble-sort

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. 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.


Solution

  • (If you don't want to use HashMaps) Just create a temp 2d array, the sort each sub-array (meaning sort all temp[i]) based on the first value in the sub-array (meaning based on temp[i][0]).