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     }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM