gpt4 book ai didi

Java 将字符串添加到字符串数组

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:44:25 24 4
gpt4 key购买 nike

<分区>

你好,我一直在尝试将 String 添加到 String[]。这是我的,

static String[] ipList = {"127.0.0.1", "173.57.51.111", "69.696.69.69"};
@Override
public void actionPerformed(ActionEvent e) {
String newIpGet = textfield.getText();
try {
for ( int i = 0; i < Main.ipList.length; i++){
Main.ipList[i+1] = newIpGet.toString(); // <---- *****
Main.write(Main.ipList[i]);
}
} catch (IOException e1) {
e1.printStackTrace();
}

Main.amountOfIps = Main.amountOfIps + 1;

System.out.println("Text Entered!");
System.out.println("There are now " +Main.ipList.length + " Ips.");
textfield.setVisible(false);

label.setVisible(true);;
}

但是,我一直收到 java.lang.ArrayIndexOutOfBoundsException,因为它不会让我创建任何新的 String。如果不进行大量修改,我无法修改我的 ipList[] 声明,我该怎么办?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com