reverse the string in java and remove the spaces.. code example Example: remove space string java a = a.replaceAll("\\s+", "");