title: Java Split and Replace String
body: <p>I got a string variable. The example of the string is like this:</p>
  
  <pre><code>abc
  12345 cde123
  hyz 
  8755 3356
  </code></pre>
  
  <p>and I want to assign an array string by splitting the whitespace become like this. And I want to take just first 4 values of it.</p>
  
  <pre><code>stringArray[0] = abc;
  stringArray[1] = 12345;
  stringArray[2] = cde123;
  stringArray[3] = hyz;
  </code></pre>
  
  <p>8755 3356  not need to assign in this array string.</p>
  
  <p>However, the <code>abc</code> and <code>12345</code> is seperate by a newline and not a whitespace. So i try to replace the newline become whitespace with my function, which is like this: </p>
  
  <pre><code>Util.replaceStr(stringX, "\n", " ");
  </code></pre>
  
  <p>To assign spilt the string into array string, i detect the index of white space which is </p>
  
  <pre><code>int index= sMessage.indexOf(" ");
  </code></pre>
  
  <p>And put it on looping </p>
  
  <pre><code>stringArray[i] = stringX.substring(0,index);
  stringX=stringX.substring(index,stringX.length()-index);
  index =stringX.indexOf(" ");
  </code></pre>
  
  <p>and assign the first 4 values into it. However after i replace the newline into whitespace, there will be double whitespace and the first four array will get like this</p>
  
  <pre><code>stringArray[0] = abc;
  stringArray[1] = ;
  stringArray[2] = 12345;
  stringArray[3] = cde123;
  </code></pre>
  
  <p>How can i assign the array string by skipping the white space value?
  <strong>THERE IS NO SPLIT FUNCTION IN NETBEAN</strong>. I know java got. =)</p>