How can I optimize this piece of code further.
And if possible, please suggest what I should usually keep in mind.
public void funct(String str, int[] arr) {
String temp = "saved";
for (int i = 0; i < arr.length; i++) {
if (str.equals(temp) && arr[i] * 2 > 10) {
Integer num = new Integer(arr[i]);
num = num * 2;
System.out.print(num.toString());
}
}
}
Thank You
Your code doesn’t make much sense as it stands, e.g.
strandtemparen’t really needed. So the first step in optimizing them is to remove them… Also useint, notInteger:And if you care about code conciseness: