字符串中重复出现字符串个数总结
访客
阅读:228
2022-05-18 12:09:55
评论:0
本文章主要介绍了字符串中重复出现字符串个数,具有不错的的参考价值,希望对您有所帮助,如解说有误或未考虑完全的地方,请您留言指出,谢谢!
1 public static void main(String[] args) { 2 String a = "1;2;1;4;5;6;7;8;9;0"; 3 String[] b = a.split(";"); 4 for (int i = 0; i < b.length; i++) { 5 int count1 = substringCount(a, b[i]); 6 System.out.println(count1); 7 if (count1 > 1) { 8 a = a.replace(b[i], ""); 9 } 10 } 11 } 12 13 public static int substringCount(String str, String substring) { 14 if (str.contains(substring)) { 15 String strReplaced = str.replace(substring, ""); 16 return (str.length() - strReplaced.length()) / substring.length(); 17 } 18 return 0; 19 }
声明
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。