If you are using Java 8 it now supports some more functional style programming, including functions such as map. Map can be applied to a stream, in this case a stream of Ints created from the String. Map applies a function (a lambda function in this case) to each member of that stream and outputs something else:
.map(x -> x)
would essentially do nothing as it would output what you input, the stream would remain unchanged. Applying the logic within the lambda function allows you to determine the output based on some conditions.
This converted stream is then collected back together into a string builder and then output as a String.
String str = "+-+";
String inverted = str.chars().map(x -> x == '+' ? '-' : '+')
.collect(StringBuilder::new,
StringBuilder::appendCodePoint,
StringBuilder::append)
.toString();
// inverted now contains "-+-"
This way there is no need to change to an intermediate character and go over the string twice, you only have to look at each character once.