-1

Given that I have the array of :

Array1 = [100,10,Banana], [101,10,Apple], [102,14,Banana], [103,12,Mango] -- size :4

I want to create a new array which is grouped by the 3rd parameter of Fruits object. So that my array becomes

ArrayFinal = [[100,10,Banana],[102,14,Banana]], [101,10,Apple], [103,12,Mango] -- size : 3

Need the help in respective to java 8. I heard that we can use the Map ,but can anyone give the small code sample or any other implementation guide.

  • you could iterate original Array1, then get the value of 3rd position and use a map to add all arrays with 3rd position equal. Then iterate that map keys and create the new ArrayFinal – cralfaro Jun 29 '21 at 10:42

1 Answers1

0

Respective to java 8

You need to use Collectors.groupingBy() static factory method

Here is blog post explaining use of java groupingby collector

Minnow
  • 495
  • 4
  • 6