Arrange the characters of the array in the order they appear in the Java string

I have a string and an array of characters in the string I want to arrange the characters in the order they appear in the string For example:

Solution

You can use this overload to sort:

Arrays.sort(chars,Comparator.comparingInt(str::indexOf));

The given character is of type character [] and STR is a string

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>