[英]How to initialize char 2d array quickly?
In C, I could initialize 2d char array using something like 在C语言中,我可以使用类似以下内容来初始化2d char数组
public static char hashTable[10][5] = {"", "", "abc", "def", "ghi", "jkl",
"mno", "pqrs", "tuv", "wxyz"};
I am wondering how to do this in Java? 我想知道如何在Java中执行此操作?
You can invoke toCharArray()
on your String
literals, the most similar construct I can think of is 您可以在
String
文字上调用toCharArray()
,我能想到的最相似的构造是
public static char[][] hashTable = {
"".toCharArray(), "".toCharArray(),
"abc".toCharArray(), "def".toCharArray(),
"ghi".toCharArray(), "jkl".toCharArray(),
"mno".toCharArray(), "pqrs".toCharArray(),
"tuv".toCharArray(), "wxyz".toCharArray()
};
You can do the following, 您可以执行以下操作
public static char[][] arr = {{'a', 'd'},{'s','w','f'}};
arr[0] references the first array which is {'a', 'd'} while arr[1] references the second arr [0]引用第一个数组为{'a','d'},而arr [1]引用第二个数组
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.