在Java中String数组初始化 [英] String array initialization in Java
本文介绍了在Java中String数组初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我声明了一个字符串
数组:
字符串名称[] =新的String [3];
那么,为什么我们不能将值分配给上述声明如下数组:
名称[] = {ANKIT,Bohra,XYZ};
解决方案
您可以做以下声明中:
字符串名称[] = {ANKIT,Bohra,XYZ};
如果你想要做的声明之后这个地方:
字符串名称[];
名称=新的String [] {ANKIT,Bohra,XYZ};
If I declare a String
array:
String names[] = new String[3];
Then why can't we assign values to the array declared above like this:
names[] = {"Ankit","Bohra","Xyz"};
解决方案
You can do the following during declaration:
String names[] = {"Ankit","Bohra","Xyz"};
And if you want to do this somewhere after declaration:
String names[];
names = new String[] {"Ankit","Bohra","Xyz"};
这篇关于在Java中String数组初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文