`
strayly
  • 浏览: 97942 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

获取一个字符串在另个字符串中出现的所有位置

    博客分类:
  • java
阅读更多
public class StringTest {

    public static void main(String args[]) {
        String s = "hello, this is a test this is a test this is a this is test";
        
        String p = "test";
        for(int i = 0;  i < s.length(); i ++) {
            int at = s.indexOf(p, i);
            
            if(at < 0) {
                break;
            }
            
            System.out.println(p + "@" + at);
            i = at;
        }
    }
}



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics