title: Java: Find the longest sequential same character array
body: <p>I am a new guy to java. I want to find the longest sequential same character array in a input character arrays. For example,this character array bddfDDDffkl, the longest is DDD， and this one: rttttDDddjkl, the longest is tttt.
  I use the following code to deal with this problem. But, I want to improve my code, For example, if there are two same length arrays (for example  rtttgHHH, there are two longest: ttt and HHH), how to solve this problem? </p>
  
  <p>Thanks in advance. </p>
  
  <p>My following code:</p>
  
  <pre><code>public class SeqSameChar {
  public static void main (String[] args) {
     int subLength = 0;
     Scanner sc = new Scanner(System.in);
     String[] num = null;
     num = sc.nextLine().split(" ");
     String[] number = new String[num.length];
  
     for(int i = 0; i&lt; number.length;i++) {
         number[i] = String.valueOf(num[i]);
     }
  
     subLength =length(number,num.length);  
     System.out.println(subLength);
  
     for(int i = index; i &lt; index+subLength; i++) {
         System.out.print(number[i]);
     }
  
     System.out.println(c==c1); 
   }
  
  
     public static int index;  
        //to calculate the longest contiguous increasing sequence  
         public static int length(String[] A,int size){  
         if(size&lt;=0)return 0;  
         int res=1;  
         int current=1;  
         for(int i=1;i&lt;size;i++){  
             if(A[i].equals(A[i-1])){  
                 current++;  
             }  
             else{  
                 if(current&gt;res){  
                     index=i-current;  
                     res=current;  
                 }  
                 current=1;  
             }  
         }  
        return res;      
       }      
     }
  </code></pre>