且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java的String数组差异

更新时间:2022-12-24 20:51:19

他们都是等价的。


      
  • 那么,是否每个这些编译?

  •   

是的,因为你自己也可以验证。

Yes, as you yourself can also verify.


      
  • 如果是的,有什么区别(如果有的话)?

  •   
  • (Test1的是性能比test2的更好,因为你不把一个新的String [] - 实例化,或者是这个反正做幕后?)

  •   

有编译字节code无差异。

There are no differences in compiled byte code.


      
  • (如果test1的是一样的TEST3:为什么TEST3和TEST4存在,如果是一样的TEST1和TEST2)

  •   

这只是写它作为数组索引可以在类型名称之后,以及标识符名称后放的另一种方式。唯一的区别是如果在一个行声明多个变量,如果索引的类型名称后放置,所有列出的标识符将是该类型的数组,而如果该索引标识符名称后放,只有标识符将是一个数组

It is just an alternative way to write it as the array indices can be put after the type name as well as after the identifier name. Only difference is if you declare multiple variable in one line, if indices are placed after the type name, all listed identifiers will be an array of that type, while if the indices are put after the identifier name, only that identifier will be an array.

示例:

String[] array1, array2;    // Both are arrays
String array3[], notArray4; // Only array3 is array

我推荐的类型后,将指数(的String []数组1 ),所以这将是unambigous。

I recommend putting indices after the type (String[] array1) so it will be unambigous.

(是否有更多的(几乎相同)的变种除了这四个?)

(Are there more (almost similar) variants apart from these four?)

不,我知道的。