Я пытаюсь заполнить массив subnetItems примером элемента ted. У меня есть отладчик открыт и вижу, что элементы в массиве остаются нулевыми даже после существующего цикла for. Я вижу, что currentItem получает значение, равное ted, но оно не входит в фактический массив. Я попытался инициализировать currentItem в каждом цикле, чтобы убедиться, что это помогает, но это не так.Можно ли заполнить массив в цикле foreach?
int startHost = 0;
int endHost = 0;
int broadcast = 0;
int subnetNumber = 0;
String fullSubnetAddress = "Start address";
String fullBroadcastAddress = "Broadcast Address";
String fullStartHost = "startHost";
String fullEndHost = "endHost";
SubnetItem ted = new SubnetItem(subnetNumber, fullBroadcastAddress, fullStartHost, fullEndHost, fullBroadcastAddress);
SubnetItem[] subnetArray = new SubnetItem[this.totalSubnets];
for (SubnetItem currentSubnet : subnetArray)
{
currentSubnet = new SubnetItem();
currentSubnet = ted;
}
System.out.println("Pause");
http://stackoverflow.com/questions/11032235/java-modifying-elements-in-a- foreach –