Static Variable for Empty String vs Double Quotes - Performance
807589Jul 23 2008 — edited Jul 24 2008I have a performance question. Say I have 5 Strings that need to be cleared. What would have better performance.
String s1 = "Test1";
String s2 = "Test2";
String s3 = "Test3";
String s4 = "Test4";
String s5 = "Test5";
Option 1:
defining a variable like this:
static String EMPTY_STRING = "";
and then doing this:
s1 = this.EMPTY_STRING;
s2 = this.EMPTY_STRING;
s3 = this.EMPTY_STRING;
s4 = this.EMPTY_STRING;
s5 = this.EMPTY_STRING;
Option 2:
The good old fashioned way:
s1 = "";
s2 = "";
s3 = "";
s4 = "";
s5 = "";
I'm just wondering if I'll notice any performance difference by doing Option 1. In my program, I have a lot more then 5 strings to clear, I was just using this as an example. (They are mostly text fields as it's a gui app)
Any thoughts on this would be great. I might just build a little performance tester myself but I was looking for advice before I did so. (A couple of my fellow developers are debating this)
Thanks.
--Ethan