Java String Popping Solution