Im trying to understand how String immutability increases the security. I had searched and found many cases but it does not give real practical example.
Here is one such example -
boolean connect(string s){
    if (!isSecure(s)) { 
        throw new SecurityException(); 
    }
    //here will cause problem, if s is changed before this by using other references.    
    causeProblem(s);
}
In the above case the connect method could be called with any valid String
For ex:- connect("DB2") or connect("ORACLE") and the method will be executed accordingly.
Can someone elaborate more on this how the security is enhanced?
Excuse if its more basic question.