Find the longest sequential same character array 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. Next example:

rttttDDddjkl


The longest is tttt.

I use the following code to deal with this problem but I want to improve my code. Could you tell me if there are any edge cases here? For example, if there are two same length arrays (for example rtttgHHH, there are two longest: ttt and HHH), how to solve this situation?

My following 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]);
    }
    }
    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;      
    }
}
The code has  a bug:

q q q u u u u u u 
3
qqq


It should be 

6
uuuuuu