Am trying to find the number of String objects created in the below code.
I think it is 4 because String
s are immutable, so each of the first two lines in prod() method will create one object, and the third line will create 2 objects. So total 4 obejcts will be created. Could anybody clarify on that?
public class Solution {
public void prod() {
String str="Sku";
str=str+"001";
String skuId= str.substring(3,6);
System.out.println(skuId.toString());
}
public static void main(String[] args) {
new Solution().prod();
}
}