Java判断字符串是否有重复

 

检测是否重复:

 1     public static boolean checkDifferent(String iniString) {
 2         boolean isbool = false;
 3         char[] chars = iniString.toCharArray();
 4         for (int i = 0; i < chars.length; i++) {
 5             for (int j = i + 1; j < chars.length; j++) {
 6                 if (chars[i] == chars[j]) {
 7                     isbool = true;
 8                     return isbool;
 9                 } else {
10                     isbool = false;
11                 }
12             }
13         }
14         return isbool;
15     }

输出重复:

 1 public static void repeat_find( String s) {
 2         for (int i = 0; i < s.length(); i++) {
 3             char c = s.charAt(i);
 4             for (int j = i + 1; j < s.length(); j++) {
 5                 if (s.charAt(j) == c) {
 6                     System.out.println("找到了重复的字符为:" + c);
 7                 }
 8             }
 9         }
10     }

猜你喜欢

转载自www.cnblogs.com/AnonymousDestroyer/p/10502632.html
今日推荐