String中查询重复字符
2016-11-04 10:19
141 查看
@Test public void test1() { String str = "aaaaddaaddababacaxaxcccaswfdsfasgdfah"; //把SIZE提前取出,免得在循环中每次都得取 int charSize = str.length(); Set<Object> rSet = new HashSet<>(); for (int j = 1; j <= charSize; j++) { for (int i = 0; i < charSize; i++) { String strE2 = null; if (i < charSize - j) { //截取的波动区间为(1~SIZE-1) strE2 = str.substring(i, i + j); System.out.println( "---" + strE2 + "---" ); //正向查找,反向查找,如果能查到则返回对应的位置 //因为是从str中截取的strE2,所以不会有indexOf()==-1的情况 int indexS = str.indexOf(strE2); int indexE = str.lastIndexOf(strE2); if(indexS != indexE){ //使用Set的特性过滤并保存重复的值 rSet.add(strE2); } } } } System.out.println(rSet); }
相关文章推荐
- 查询出删除身份证号前后的特殊字符后重复的行并删除
- C# String操作(字符重复出现,截取字符,连接字符)
- 一个字符串中可能包含a~z中的多个字符,如有重复,如String data="aavzcadfdsfsdhshgWasdfasdf",求出现次数最多的那个字母及次数,如有多个重复的则都求出。
- JAVA面试题之String处理--一字符取出重复的字符以及其个数
- c# String.Join 和 Distinct 方法 去除字符串中重复字符
- 一个字符串中可能包含a~z中的多个字符,如有重复,如String data="aavzcadfdsfsdhshgWasdfasdf",求出现次数最多的那个字母及次数,如有多个重复的则都求出。
- 在String里找出字符重复次数
- String.Join 和 Distinct 方法 去除字符串中重复字符
- 获取String 中第一个不重复字符
- [LeetCode] First Unique Character in a String 寻找第一个不重复出现的字符
- String——求没有重复字符的最长的子串
- 一个很不错的查询重复字符的方法
- 获取String 中重复次数最多的字符
- 检查一个string里面是否有重复的字符
- C# 使用String.Join 和 Distinct 方法 去除字符串中重复字符
- Java删除字符串中重复的String类型的字符
- oracle查询某个字段重复数据以及截取字符、查找字符下标
- 要求查询“"Welcome to Chinaworld"“中重复的字符,不区分大小写,并且打印出来每个字符出现的次数
- 一道递归算法--String[] 里面的字符无重复的排序
- 【原创】打印一个string 字符串中重复字符的次数