在php中,可以像我们想要的那样操作字符串,例如:
$temp2 = array();
$theindex = 0;
foreach($arraysimpanloop as $a) {
$temp1 = array();
for($i = 0; $i < sizeof($a)-1; $i++) {
$temp1[$i] = $a[$i];
}
natsort($temp1); // sort array temp1
$stringimplode = implode($temp1);
$temp2[$theindex] = $stringimplode;
$theindex++;
}
由于我现在正在使用Java,因此我想知道如何:
$temp2[$theindex] = $stringimplode;
用Java代码编写。因为我在java中尝试过:
temp2[theindex]= stImplode; // here temp2 is array of string
它总是返回一个空指针。
最佳答案
您的字符串数组可能尚未初始化
int yourSize = ...;
String[] temp2 = new String[yourSize];
这就是为什么您可能会得到空指针的原因。
或者您从不存在的数组中访问元素(例如,您的数组有100个元素,而您尝试访问101个元素)