日期:2014-05-20 浏览次数:20808 次
public static int Continumax(String intputStr, StringBuffer outputStr) {
char[] charArray = intputStr.toCharArray();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < charArray.length; i++) {
if (Character.isDigit(charArray[i])) {
sb.append(charArray[i]);
} else {
sb.append(",");
}
}
String[] digitArray = sb.toString().replaceAll("(,)+", ",").split(",");//得到数字数组
if (digitArray.length <= 1) {
System.out.println("没有数字串!");
return 0;
}
List<String> digitList = new ArrayList<String>(Arrays.asList(digitArray));//转化为list方便操作
List<String> positiveDigitList = fetchContinueDigitByPositiveSort(digitList, true);//得到正向连续的数字比如1234,345
List<String> backDigitList = fetchContinueDigitByPositiveSort(digitList, false);//得到反向连续的数字比如4321,765
List<String> lastList = new ArrayList<String>();
lastList.addAll(positiveDigitList);
lastList.addAll(backDigitList);
int maxLength = 0;
String maxValue = "";
List<String> endStrList = new ArrayList<String>();
for (String s : lastList) { //找出最长并且是最后一个的值和长度