title: Formatting String Array efficiently in Java
body: <p>I was working on some string formatting, and I was curious if I was doing it the most efficient way.</p>
  
  <p>Assume I have a String Array:</p>
  
  <pre><code>String ArrayOne[] = {"/test/" , "/this/is/test" , "/that/is/" "/random/words" }
  </code></pre>
  
  <p>I want the result Array to be</p>
  
  <pre><code>String resultArray[] = {"test", "this_is_test" , "that_is" , "random_words" }
  </code></pre>
  
  <p>It's quite messy and brute-force-like.</p>
  
  <pre><code>for(char c : ArrayOne[i].toCharArray()) {
        if(c == '/'){
              occurances[i]++;
        }
     }
  </code></pre>
  
  <p>First I count the number of "/" in each String like above and then using these counts, I find the indexOf("/") for each string and add "_" accordingly.</p>
  
  <p>As you can see though, it gets very messy. </p>
  
  <p>Is there a more efficient way to do this besides the brute-force way I'm doing?</p>
  
  <p>Thanks!</p>