You are reading from a properties file in java. Would you like the values to be trimmed already, or would you like the control to yourself?
What actually happens?
Whenever you read from a property file, the values you get are left trimmed and not right trimmed. I love the expression on your face right now. Yes it is actually true.
Consider a property file properties.properties,
- value1 has no spaces on the left or right. (‘value1’)
- value2 has two spaces on the left. (’ value2’)
- value3 has two spaces on the right. (‘value3 ’)
- value4 has two spaces each on the left and right side. (’ value4 ’)
When, you fetch the value using,
Properties prop = new Properties();
The values returned are –
prop.getProperty('prop1') returns 'value1'
prop.getProperty('prop2') returns 'value2'
prop.getProperty('prop3') returns 'value3 '
prop.getProperty('prop4') returns 'value4 '
Thus, please (right) trim the values before using them. 😉