国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

統計某個字符串出現的次數或者是否存在

2019-11-08 18:30:10
字體:
來源:轉載
供稿:網友

統計某個字符串出現的次數

判斷testStr字符串或者字符testChar是否存在目標字符串中targetStr

package sun.rain.amazing;import org.apache.commons.lang3.StringUtils;import org.junit.Test;/** * 統計某個字符串出現的次數 * 判斷testStr字符串或者字符testChar是否存在目標字符串中targetStr * @author sunRainAmazing * */public class StringApPRanceCount { public static String STRING ="i am a student . hello world , day day up , good good study !"; public static String STR = "good"; /** * 采用Apache下的工具類才進行測試 */ @Test public void getCount(){ System.out.println(StringUtils.countMatches(STRING, STR)); } /** * 采用String內部的長度來進行測試 */ @Test public void testLength(){ int firstLength = STRING.length(); int lastLength = STRING.replace(STR, "").length(); int count = (firstLength-lastLength)/3; System.out.println("出現的次數"+count); System.out.println("出現的次數"+(STRING.length()-STRING.replace(STR, "").length())/3); } /** * 判斷是否存在某個字符串內容 * indexOf() ---若不存在返回 -1 */ @Test public void isExists(){ if(STRING.indexOf(STR) != -1){ System.out.println("存在"); } System.out.println(STRING.indexOf(STR) != -1? STR+"存在"+STRING:STR+"不存在"+STRING); }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 林周县| 拜泉县| 泰和县| 兴国县| 华亭县| 阜平县| 阳原县| 新安县| 黎平县| 瑞丽市| 乌兰察布市| 饶平县| 大理市| 永城市| 锦州市| 锦屏县| 揭阳市| 文登市| 南丹县| 景东| 西城区| 六盘水市| 农安县| 格尔木市| 梁河县| 平和县| 神农架林区| 罗源县| 曲周县| 长治县| 抚顺市| 方正县| 离岛区| 华蓥市| 江西省| 迁安市| 洞头县| 芦溪县| 南漳县| 建宁县| 迁安市|