 <p>This is an example of code that works for me. It performs these operations:</p> <ol> <li>It splits the string based on whitespace, and each element is stored on an array of strings;</li> <li>It checks the size of each element of the array;</li> <li>If the size is == 4 (the number of characters of the postal code), then it checks (with a pattern) if the current element is a number;</li> <li><p>If the current element is a number, then this element and the next element (the city) is stored on an <a href="http://docs.oracle.com/javase/6/docs/api/java/util/ArrayList.html" rel="nofollow">ArrayList</a>.</p> <pre><code>import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.*; public class split{ private List&lt;String&gt; newline = new ArrayList&lt;String&gt;(); public split(){ String myString = "Graaf Karel De Goedelaan 1 8500 Kortrijk"; String array[] = myString.split("\\s+"); for(int z = 0;z&lt;arr.length;z++){ int sizestr = array[z].length(); if(sizestr==4){/* if the generic string has 4 characters */ String expression = "[0-9]*"; CharSequence inputStr = array[z]; Pattern pattern = Pattern.compile(expression); Matcher matcher = pattern.matcher(inputStr); if(matcher.matches()){/* then if the string has 4 numbers, we have the postal code" */ newline.add(array[z]); /* now we add the postal code and the next element to an array list" */ newline.add(array[z+1]); } } } Iterator&lt;String&gt; itr = newline.iterator(); while (itr.hasNext()) { String element = itr.next(); System.out.println(element); /* prints "8500" and "Kortrijk" */ } } public static void main(String args[]){ split s = new split(); } } </code></pre></li> </ol> <p>For further info about the check of the string, take a look to this <a href="http://www.zparacha.com/best-way-to-check-if-a-java-string-is-a-number/#.T1TX_ZeA8vs" rel="nofollow">page</a>, and, for the ArrayList Iterator, see <a href="http://www.java2s.com/Code/JavaAPI/java.util/ArrayListiterator.htm" rel="nofollow">this</a>.</p> <p>I hope this can help to solve your problem.</p>