国产探花免费观看_亚洲丰满少妇自慰呻吟_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); }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 通辽市| 肇州县| 济源市| 庆阳市| 沿河| 峨眉山市| 黔南| 进贤县| 山东| 汕尾市| 北京市| 鲜城| 达日县| 永年县| 肇州县| 南靖县| 农安县| 股票| 商水县| 海伦市| 邢台县| 香格里拉县| 东方市| 清远市| 镇巴县| 丹东市| 开封县| 宁陕县| 沙河市| 东乌| 贵南县| 商河县| 阜阳市| 卓资县| 陆川县| 汉沽区| 临泉县| 延吉市| 三门峡市| 三门峡市| 新泰市|