title: Run a for loop until the String Condition in JAVA
body: <p>If I have a String array as follows.</p>
  
  <pre><code> String[] name = {"aval", "H ---- ", "Singh", "Sawh", "Raman", " ---- ", "parminder", "kaur", "jaspreet", "asneet", " ---- "};
  </code></pre>
  
  <p>I want to copy all the contents from between "H ---- " to " ---- ". That is it should be "SinghSawhRaman" (excluding "H ---- " and " ---- ".</p>
  
  <p>Something like this:</p>
  
  <pre><code>String keywords = "";
  int j = 0;
  for(int i = 0; i &lt; name.length; i++){
   if(name[i].contains("H ---- ")){
     for(j = i; j &lt; 5; j++){       
      // There problem is j &lt; 5. I want to give a condition when name[i].contains(" ---- ") 
      // but not sure how should I be able to do it.
     keywords = keywords + name[j];
    }
  </code></pre>
  
  <p>Can someone please show me the best way to do this?     </p>