How to change the value of array elements

前端 未结 7 2027
情歌与酒
情歌与酒 2020-12-21 10:57
int A = 300;
int B = 400;
int C = 1000;
int D = 500;

int []abcd = {A,B,C,D};
Arrays.sort(abcd);   // the sequence of array elements will be {300, 400, 500,1000}
         


        
7条回答
  •  南笙
    南笙 (楼主)
    2020-12-21 11:18

    What you want is a mapping from value to array location. Unless there's a way to get such a mapping out of Arrays.sort(), which I doubt (though I'm no Java expert), you'll need to generate the mapping yourself. You could do this by searching the array. It might be more efficient to implement your own sort so that you can keep track of the mapping as you sort the array.

提交回复
热议问题