Java怎样判断字符串中是否有连续的值

[复制链接]
查看11 | 回复4 | 2016-4-16 20:33:05 | 显示全部楼层 |阅读模式
把要判断的字符串放入List里面,然后遍历list集合,如果还有指定的字符就输出,如下代码:package com.qiu.lin.he;import java.util.ArrayList;import java.util.List;public class Ceshi {public static void main(String[] args) {List list = new ArrayList();//新建一个集合list.add("puton");list
回复

使用道具 举报

千问 | 2016-4-16 20:33:05 | 显示全部楼层
您所谓的连续值是指任意字符之间连续?如:String str="aaabcdeefgbc";
三个“a”、两个“e”连续;
“bc”连续是吗?如果是这样的话就比较麻烦。
回复

使用道具 举报

千问 | 2016-4-16 20:33:05 | 显示全部楼层
有个办法就是String str="aaab ccc";int len=str.length();String str1=str.trim(); int len1=str1.length();if(len1>len){说明字符串不连续}else{ 连续}这样写可以降低内存使用,程序得以优化
回复

使用道具 举报

千问 | 2016-4-16 20:33:05 | 显示全部楼层
String a;int length = a.GetLength();boolean hasContinuousValue = falsefor( int i=0; i<length-1; i++)
if( a.charAt(i) == a.charAt(i+1) )
{ hasContinuousValue = true;
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行