日期:2014-05-20  浏览次数:20750 次

String arg : cmd 这是什么用法?
今天看到代码:

 public static NativeProcess executeCmd(String[] cmd, String[] env, String dirName) {
   
  Runtime rt = Runtime.getRuntime();
  File dir = null;
  Process process = null;

  /* Check if one of the arguments in the array is not null by chance... */
  for (String arg : cmd) {
  if (arg == null) {
  return null;
  }
  }

粗体的那句不明白这是什么用法,请高手解答, 谢谢!

------解决方案--------------------
引用楼主 yazi0127 的帖子:
今天看到代码:

public static NativeProcess executeCmd(String[] cmd, String[] env, String dirName) {

Runtime rt = Runtime.getRuntime();
File dir = null;
Process process = null;

/* Check if one of the arguments in the array is not null by chance... */
for (String arg : cmd) {
if (arg == null) {
return…

------解决方案--------------------
String[] cmd
遍历这个cmd数组啊.增强for循环.不会不知道吧.
真不知道lz是什么意思
------解决方案--------------------
for(String arg:cmd){

}
就是
for(int i=0;i<cmd.length;i++){

}
是java 5的新特性
------解决方案--------------------
for (String arg : cmd)形式是jdk1.5.0以后的加进来的新特征,增强的for循环语句,比如
for(type variable : array){
body
}
还原以前的版本的形式为
for(int i=0;i<array.length;i++){
type variable=array[i];
body
}