title: How to return longest sequence of chars in a string in java?
body: <p>Following is what I end up doing but i did not find right answer.</p>
  
  <p>Example - If I have the sequence "hellloo" the output will be "lll". Please tell me what is wrong?</p>
  
  <pre><code>public class LongestSequenceOfChar {
      static String testcase1="hellloo";
  
      public static void main(String[] args) {
          LongestSequenceOfChar test = new LongestSequenceOfChar();
          String result = test.longestSequenceOfChar(testcase1);
          System.out.println(result);
      }
      public String longestSequenceOfChar(String str){
          String result="";
          for(int i=0;i&lt;str.length();i++){
              char ch=str.charAt(i);
              for(int j=i+1;j&lt;str.length();j++){
                  char ch1=str.charAt(j);
                  if(ch!=ch1){
                      continue;
                  }
                  result+=ch;
              }
          }
          return result;
      }
  }
  </code></pre>