我对一个给定数组的长度进行了很多调用,我想知道是否更好地继续调用它(目前已经超过50次,但它会不断增长)或者将长度存储在整数中是否更好并使用每次都是整数.
如果我不清楚我在说什么,请考虑以下事项:
我有一个String数组:
String[] str = new String[500]; //The length is actually dynamic, not static
Run Code Online (Sandbox Code Playgroud)
当然,我在其中添加了一些值,但是我在整个应用程序中始终调用字符串的长度:
int a = str.length;
int b = str.length;
int c = str.length;
int d = str.length;
int e = str.length;
Run Code Online (Sandbox Code Playgroud)
等等...所以这样做更好:(表现明智,不要那么关心记忆)
int length = str.length;
int a = length;
int b = length;
int c = length;
int d = length;
int e = length;
Run Code Online (Sandbox Code Playgroud)
谢谢.
归档时间: |
|
查看次数: |
2455 次 |
最近记录: |