Checking if 2 strings contain the same characters?

前端 未结 10 898
孤城傲影
孤城傲影 2020-12-10 04:49

Is there a way to check if two strings contain the same characters. For example,

abc, bca -> true
aaa, aaa -> true
aab, bba -> false
abc, def ->          


        
10条回答
  •  抹茶落季
    2020-12-10 05:21

    As a (nitpicking ;-) ) side note:

    Be aware that the solutions proposed here only work for strings composed of characters from the Basic Multilingual Plane (BMP) of Unicode.

    Characters outside the BMP are represented as a pair of char in a String, so you need to pay extra attention, so you keep the pairs together. See the Javadocs of java.lang.Character for the gory details.

    Fortunately, most characters outside the BMP are rather exotic. Even most of Japanese and Chinese is in the BMP...

提交回复
热议问题