How to get the index and max value of an array in one shot?

后端 未结 4 1903
我寻月下人不归
我寻月下人不归 2020-12-05 15:58

Given a list of integer elements, how to get the max value and it\'s index in one shot. If there is more than one element with same max value, returning index of any one of

4条回答
  •  萌比男神i
    2020-12-05 16:49

    In java8 you can execute streams in parallel

    Integer[] intArr= {1,2,6,2,234,3,54,6,4564,456};
    
    IntStream.range(0, intArr.length-1).parallel().
                    reduce((a,b)->intArr[a] System.out.println("Index: " + ix + ", value: " + intArr[ix]));
    

提交回复
热议问题