unnecessarily assign values to variables. It increases the use of RAM memory. A noter que la JVM optimise de toute façon ce code lors de la compilation de la version sale à la version green.
(String string : strings) { result += string; } return result; } public String concatenateStrings(String[] strings) { StringBuilder result = new StringBuilder(); for (String string : strings) { result.append(string); } return result.toString(); } Don't concatenate Strings in loop. Use StringBuilder instead. Strings are immutable so each time you concatenate a String, a new String is created. This is a waste of memory and CPU.
getMyValue(); i++) { System.out.println(i); } } public voidfoo() { int myValue =getMyValue(); for (int i = 0; i < myValue; i++) { System.out.println(i); } } Do not call a function when declaring a for-type loop in order to avoid function calls each iterations. It saves CPU cycles.