UMC.TOSTRING

A UMC.TOSTRING warning appears if there is a call to the toString() method on a string argument. Removing such call can help optimize the code in certain cases.

Vulnerability and risk

This method creates extra objects which take up more memory and reduce performance, without any other functional effect.

Example 1

Copy
     ArrayList bool1(String arr[]) {
         ArrayList res = new ArrayList();
         for (int i = 0; i < arr.length; i++) {
             String b = arr[i];
             res.add(b);
         }
         return res;
     }
     // correct one
     ArrayList bool2(String arr[]) {
         ArrayList res = new ArrayList();
         for (int i = 0; i < arr.length; i++) {
             String b = arr[i];
             res.add(b.toString());
         }
         return res;
     }

UMC.TOSTRING is reported for line 25: Unnecessary toString() method is called for String argument. Use argument instead