Java 字符串名称[]={}之间的区别是什么;和字符串[]name={};
我用java写了这段代码,我在想做这件事有什么区别:Java 字符串名称[]={}之间的区别是什么;和字符串[]name={};,java,Java,我用java写了这段代码,我在想做这件事有什么区别:String[]whatever和String-whatever[],如果有人能告诉我发生了什么,最好使用String[]whatever={}或者使用String-whatever[]={}或者这是不推荐的 public class Snippet136 { public static void main(String [] args) { String names[] = {"Jhonny", "Edur
String[]whatever
和String-whatever[]
,如果有人能告诉我发生了什么,最好使用String[]whatever
={}或者使用String-whatever[]
={}或者这是不推荐的
public class Snippet136
{
public static void main(String [] args)
{
String names[] = {"Jhonny", "Edurardo", "Francis", "Franklin", "Freedy"};
String [] eyes_colors = { "blue", "red", "black", "green", "black"};
System.out.print("Names:");
for (String name: names) {
System.out.print( " " + name );
}
System.out.print("\n\nEyes colors:");
for ( String eyes_color: eyes_colors ) {
System.out.print( " " + eyes_color );
}
}
}
完全没有:这两种形式完全相同
String[]var
更自然,通常更受欢迎(因为它更符合逻辑地将数组类型与类型名称结合起来)stringvar[]
在Java中基本上是因为C/C++使用这种语法,所以它是一种“语法兼容性”
请注意,后缀
[]
导致了一些非常疯狂的语法特性,例如能够编写int function()[]{return null;}
:函数返回int[]是的,有区别:
仅阵列:
String[] arr1, arr2;
不仅仅是阵列:
String arr1[], str1, arr2[], str2;
可能重复的