/*判断指定字符出现了几次*/ public static int countStr(String str, char key) { int count = 0; for (int i = 0; i < str.length(); i++) { if (str.charAt(i) == key) count++; } return count == 0 ? -1 : count; } /*根据指定字符截取字符串存入到数组中*/ private static String[] stringToArray(String str, String key) { String[] temp = null; temp = str.split(key); return temp; }
MainText.java
public static void main(String[] args) { String str = "abc;abck;abc"; // System.out.println(countStr(str, ';')); String [] temp = null; temp=stringToArray(str, ";"); for (int i = 0; i < temp.length; i++) { System.out.println(temp[i]); } }
转载于:https://www.cnblogs.com/dingxiansen/p/7098988.html
相关资源:String 字符串截取,获得指定字符数量,截取String两个内容之前内容并去重.pdf