The Daily WTF
If you want to configure a Java application, the standard way to do it is to use the Java Properties class. This class wraps around a simple, text-based file format (or an XML file, if you’re into that) that allows you to store key/value pairs. It helpfully inherits from the HashMap class, letting you interact with those key/value pairs using a well understood API. The file format handles all the details of encoding and managing things like multiline strings.
So you could just do that. Or, you could do what this senior dev with over a decade of experience did.
// We start with a String called reason containing text like: // “It seemed like a good ideanIt was cheapernI didn’t expect to get caught” String[] reasons = reason.split(“n”); StringBuilder builder = new StringBuilder(); for (int i = 0; i < reasons.length; i++) { if (i == reasons.length – 1)
To read the full article click on the 'post' link at the top.