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 }