You can check it out yourself.
public static void main(String... args) { long free1 = free(); String[] two = new String[2]; long free2 = free(); String[] twenty = new String[20]; long free3 = free(); if (free3 == free1) System.err.println("You need to use -XX:-UseTLAB"); System.out.println("String[2] took " + (free1 - free2) + " bytes and String[20] took " + (free2 - free3) + " bytes."); } private static long free() { return Runtime.getRuntime().freeMemory(); }
prints
String[2] took 24 bytes and String[20] took 96 bytes.
Thus, you can spend 72 bytes of memory. If your memory costs $ 10 per GB, you can spend 0.000072 cents on memory. However, a second of your time can cost 2 cents. In this case, itโs literally not worth spending a millisecond, worrying about it in this case. those. the time it takes to record 20 instead of 2 costs a lot more.
source share