I have an object retrieved from a form. It can contains some unwanted characters like "/n". I would like to remove them. I've found a way of doing it but I'm pretty sure it's possible to do it in a cleaner and shorter way?
List<Client> clients1 = pc.getClients();
List<Client> clients2 =new ArrayList<Client>();
if (clients1 != null) {
for (Client tc : clients1) {
tc.setClientId(tc.getClientId().replaceAll("\\p{C}", ""));
tc.setClientName(tc.getClientName().replaceAll("\\p{C}", ""));
tc.setCallFirstName(tc.getClientFirstName().replaceAll("\\{C}",""));
clients2.add(tc);
}
}
pc.setClients(client2)
Any suggestions? The point of this question for me is to learn how to make better code.