I have the following code which is adding somestrings to an arraylist. It will ever so often have an empty variable due to someone not filling it in correctly. I don't own the usr object so I can't modify it unfortunately. Is there a clean and easy way of just adding a default value if one of these values is empty? I don't mind if its empty, but I don't want the program to crash out!
results.add(usr.getName());
results.add(usr.getAbout());
results.add(usr.getBirthday());
results.add(usr.getEmail());
results.add(usr.getGender());
results, seems it must be generic Collection. One of the elegant ways to handle nulls is to have your own subclass of List (or otherCollection), which will handle addingnull's as you wish.