java之判断两个字符串是否互为变位词

 

package test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.alibaba.fastjson.JSONObject;


public class A {
	public static void main(String[] args) {
		String str = "live";
		String str2 = "veil";
		char[] charArray = str.toCharArray();
		char[] charArray2 = str2.toCharArray();
		Arrays.sort(charArray);
		Arrays.sort(charArray2);
		
		if(Arrays.equals(charArray, charArray2)) {
			System.out.println(true);
		}else {
			System.out.println(false);
		}
	}
}

猜你喜欢

转载自blog.csdn.net/kxj19980524/article/details/86637770