我是java初学者,我试图循环地址数组(address[]),但我不知道数组的大小,也无法检查数组的终点。 这是我的代码:
int j=0;
System.out.println(j);
while(msg.getRecipients(Message.RecipientType.CC)[j]!=null)
{cc =cc.concat(msg.getRecipients(Message.RecipientType.CC)[j].toString());
cc =cc.concat(",");
j++;
System.out.println(j);}
}
基本上 msg.getRecipients(Message.RecipientType.CC) 是地址类型的数组,当 irun 时我收到错误:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at test2.main(test2.java:135)
最佳答案
来自JLS有
public final
fieldlength
-
所以,应该是这样的 -
int j=0;
while(j < msg.getRecipients(Message.RecipientType.CC).length)
{
System.out.println(j);
cc = cc.concat(msg.getRecipients(Message.RecipientType.CC)[j].toString());
cc = cc.concat(",");
j++;
}
关于java - 在地址数组中循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23890957/