I am declaring a String array as:
String[] items1 = new String[5];
String[] items2 = new String[20];
How much effect both of these arrays will produce on memory and performance if both contain only 2 elements.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can test this yourself.
prints
So you could be wasting 72 bytes of memory. If your memory cost $10 per GB, you could be wasting 0.000072 cents of memory. However, a second of your time could be worth 2 cents. In this case it is literally not worth spending a milli-second worrying about it in this case. i.e. The time it takes to write 20 instead of 2 is worth far, far more.