package com.heima.gaoshuai;
public class Test {
public static void main(String[] args) {
containsStrNum("hanbasdnbafllgnbahjnbakqqqqlnbaxi","nba");
}
/**
* 设计一个方法,用于获取一个字符串中指定子串出现的次数,
* 比如说“hanbasdnbafllgnbahjnbakqqqqlnbaxi”中有几个nba?
*/
public static void containsStrNum(String srcStr,String containsStr){
String[] spilted = srcStr.split(containsStr);
System.out.println("字符串“"+srcStr+"”中有"+(spilted.length-1)+"几个"+containsStr+"");
}
}
|
|