Java doc says `String.trim()` Returns a copy of the string.

I have below code in my method, it does `trim` as mentioned and results in creating new string thrice.

```
String foo = getFoo(storedProcedureResult);
if(foo !=null && !foo.trim().isEmpty()){ // --> creates new string
  if(foo.trim().substring(1).equals("bar")){ // --> creates new string
  } else if(foo.trim().substring(4,6).equals("bar")){ // --> creates new string
  }
}

```

I made an attempt to minimize this with below code:

```
 String foo = getFoo(storedProcedureResult);
    if(foo !=null && !(foo=foo.trim()).isEmpty()){ // --> creates new string only once
      if(foo.substring(1).equals("bar")){ 
      } else if(foo.substring(4,6).equals("bar")){ 
      }
    }

```

Now, Sonar reports `Assignments should not be made from within sub-expressions`. How do I efficiently minimize the usage of `trim` in my method? I am bothering because this method is being used in production and invoked 250+ times per second and should not create more `String` objects unnecessarily.