提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
是介于两个字符串值之间的字串
//package com.nowjava; import java.util.HashMap; /** 来 自 N o w J a v a . c o m - 时代Java **/ public class Main { public static void main(String[] argv) throws Exception { String str1 = "nowjava.com"; String str2 = "nowjava.com"; System.out.println(isAnagram(str1, str2)); } @SuppressWarnings("boxing") public static boolean isAnagram(String str1, String str2) { if (str1 == null || str2 == null) { return false; }/*来自 NowJava.com*/ HashMap<Character, Integer> charCount = new HashMap<Character, Integer>(); for (char ch1 : str1.toLowerCase().toCharArray()) { if (!Character.isWhitespace(ch1)) { if (charCount.containsKey(ch1)) { charCount.put(ch1, charCount.get(ch1) + 1); } else { charCount.put(ch1, 1); } } } for (char ch2 : str2.toLowerCase().toCharArray()) { if (!Character.isWhitespace(ch2)) { if (!charCount.containsKey(ch2)) { return false; }