Java 是否将int添加到字符串名称的末尾?
因此,我正在寻找一种临时存储值的方法,以便在必要时将其删除(我可能会以完全错误的方式执行此操作,如果我错了,请更正我!) 我创建了18个字符串:info1、info2、info3等等 我想根据用户所处的孔将每一个设置为某个值,这就是我所描绘的Java 是否将int添加到字符串名称的末尾?,java,string,int,Java,String,Int,因此,我正在寻找一种临时存储值的方法,以便在必要时将其删除(我可能会以完全错误的方式执行此操作,如果我错了,请更正我!) 我创建了18个字符串:info1、info2、info3等等 我想根据用户所处的孔将每一个设置为某个值,这就是我所描绘的 hole = 1; info + hole = current; <--- current is a string with a value already. hole++; hole=1; 信息+孔=当前 这是错误的做法 info + 1 = 2
hole = 1;
info + hole = current; <--- current is a string with a value already.
hole++;
hole=1;
信息+孔=当前 这是错误的做法
info + 1 = 2;
不同于
info1 = 2;
你需要把东西放到一个数组中,然后进行操作
因此,对于18个字符串,将数组定义为
String[] info = new String[18];
然后再做
info[hole-1] = current;
下面是关于java中基本数组的精彩教程供参考这是一种错误的方法
info + 1 = 2;
不同于
info1 = 2;
你需要把东西放到一个数组中,然后进行操作
因此,对于18个字符串,将数组定义为
String[] info = new String[18];
然后再做
info[hole-1] = current;
以下是java FYI中关于基本数组的精彩教程制作字符串
数组:
String[] info = new String[18];
// ....
hole = 1;
info[hole] = current;
hole++;
制作一个字符串数组:
String[] info = new String[18];
// ....
hole = 1;
info[hole] = current;
hole++;
这在语法上是错误的。处理大量变量时,应使用数组或列表。在这种情况下,创建一个字符串数组。您的代码应该是这样的:
String info[] = new String[18];
String current = "something";
int hole = 1;
info[hole-1] = current; // string gets copied, no "same memory address" involved
hole++;
较短的代码段:
String info[] = new String[18], current = "something";
int hole = 1;
info[hole++ - 1] = current; // hole's value is used, THEN it is incremented
继续学习更多内容。这在语法上是错误的。处理大量变量时,应使用数组或列表。在这种情况下,创建一个字符串数组。您的代码应该是这样的:
String info[] = new String[18];
String current = "something";
int hole = 1;
info[hole-1] = current; // string gets copied, no "same memory address" involved
hole++;
较短的代码段:
String info[] = new String[18], current = "something";
int hole = 1;
info[hole++ - 1] = current; // hole's value is used, THEN it is incremented
浏览以了解更多信息。由于字符串数组是零索引的,所以它应该是info[hole-1]=当前的。
因为字符串数组是零索引的,所以它应该是info[hole-1]=当前的。