Question: Strings are immutable, does it mean that i always have to do something like that with a string passed to a method?

```
str= str.toLowerCase();

```

or is 

```
str.toLowerCase();

```

fine? I tried the second one and it doesn't give me any errors, why?

Answer: 
> 
> String are immutable
> 
> 
> 

Yes, by your own admission. An immutable *object* is one that does not allow its state to be changed. This includes `String` objects.

Then:

```
str.toLowerCase();

```

Creates a *new string* of lower-case characters and *does not use the result*. This is likely a "bug" in this case as `str` still evaluates to the original string object (which was *not* changed because it is immutable).

**There is no compiler error because Java has no way of knowing that the return value was "supposed to be used".** There are times when a method is called for side-effects, even if it also returns a value\*. This could be judged to be an error in some pure languages (those without side-effects), but it is not possible in a language with side-effects in general. Some static analysis tools -- not javac, which is just a compiler with a primitive set of warnings -- are capable of detecting such bugs as the above by applying additional heuristic rules.

Ditto, but assigns the *new string* to the *same variable*: (Variables are *not* values/objects.)

```
str = str.toLowerCase();

```

However, there is *no requirement* that the same variable is re-assigned to. Consider the following examples, which may be entirely valid in context:

```
String normalizedTitle = title.toLowerCase();
foo.setTitle(normalizedTitle);
// or, skip normalizedTitle, etc.
foo.setTitle(title.toLowerCase());

```

Happy coding.

---

\*An example of relatively common method that causes a side-effect *and* returns a value that is normally ignored is [`List.remove(int)`](http://docs.oracle.com/javase/6/docs/api/java/util/List.html#remove%28int%29).
First one. Re-assign it.

```
str= str.toLowerCase();

```