Java 如何将arraylist字符串值增加1

Java 如何将arraylist字符串值增加1,java,arrays,arraylist,Java,Arrays,Arraylist,有两个for循环,我想从内部for循环将字符串类型的数组列表值增加1。我怎么能做到 ArrayList<String> location; //Location and distanceInMiles are ArrayList<String> type and i have store some value into it. ArrayList<String> distanceInMiles; for(String strloc : location){

有两个for循环,我想从内部for循环将字符串类型的数组列表值增加1。我怎么能做到

ArrayList<String> location; //Location and distanceInMiles are ArrayList<String> type and i have store some value into it. 
ArrayList<String> distanceInMiles;
for(String strloc : location){
    for(String strDist : distanceInMiles){
        System.out.println("For Location :" + strloc + "Zip code 30303" + "Distance in Miles:" + strDist);// After print the value i want to increment strDist value by one
        break;
    }
}
ArrayList位置//Location和distanceInMiles是ArrayList类型,我在其中存储了一些值。
阵列列表距离(英里);
for(字符串strloc:location){
用于(字符串标准:距离单位英里){
System.out.println(“对于位置:“+strloc+”邮政编码30303“+”以英里为单位的距离:“+strDist”);//打印完值后,我想将strDist值增加1
打破
}
}

字符串不能递增。因此,您不必将
strist
字符串传递给
PrintStream
,而可以将字符串解析为
整数
,并执行如下操作:

System.out.printf("For Location : %s, Zip code 30303. Distance in Miles: %d%n", strloc, Integer.valueOf(strDist) + 1);

字符串不能递增。因此,您不必将
strist
字符串传递给
PrintStream
,而可以将字符串解析为
整数
,并执行如下操作:

System.out.printf("For Location : %s, Zip code 30303. Distance in Miles: %d%n", strloc, Integer.valueOf(strDist) + 1);

ArrayList可以保存一个对象列表,因此不能使用类型字符串对其进行迭代

修复此问题后,strDist仍不会继续进行下一次迭代。这是因为break语句,请删除它

您可以执行以下操作:

for (Object strDist : distanceInMiles) {

            System.out.println("For Location :" +strloc+ "Zip code 30303" + "Distance in Miles:" + strDist);// After print the value i want to increment strDist value by one

             // remove break
        }

ArrayList可以保存一个对象列表,因此不能使用类型字符串对其进行迭代

修复此问题后,strDist仍不会继续进行下一次迭代。这是因为break语句,请删除它

您可以执行以下操作:

for (Object strDist : distanceInMiles) {

            System.out.println("For Location :" +strloc+ "Zip code 30303" + "Distance in Miles:" + strDist);// After print the value i want to increment strDist value by one

             // remove break
        }
ArrayList位置//Location和distanceInMiles是ArrayList类型,我在其中存储了一些值。
阵列列表距离(英里);
for(字符串strloc:location){
ArrayList clone=(ArrayList)distanceInMiles.clone();
距离以英里为单位。清除();
for(字符串strist:clone){
System.out.println(“对于位置:“+strloc+”邮政编码30303“+”以英里为单位的距离:“+strDist”);//打印完值后,我想将strDist值增加1
add(Integer.parseInt(strdit)+1+“”);
打破
}
}
希望有帮助

ArrayList位置//Location和distanceInMiles是ArrayList类型,我在其中存储了一些值。
阵列列表距离(英里);
for(字符串strloc:location){
ArrayList clone=(ArrayList)distanceInMiles.clone();
距离以英里为单位。清除();
for(字符串strist:clone){
System.out.println(“对于位置:“+strloc+”邮政编码30303“+”以英里为单位的距离:“+strDist”);//打印完值后,我想将strDist值增加1
add(Integer.parseInt(strdit)+1+“”);
打破
}
}

希望有帮助

为了进行增量,您必须通过插入字符串到浮点的转换步骤来更改算法(我假设距离表示为字符串中的浮点)

列表位置;
以英里为单位列出距离;
for(字符串strloc:location){
对于(int i=0;i
为了实现增量,您必须通过插入字符串到浮点的转换步骤来更改算法(我假设距离表示为字符串中的浮点)

列表位置;
以英里为单位列出距离;
for(字符串strloc:location){
对于(int i=0;i
字符串不是数值。不能“递增”字符串。将其设置为整数,这样您就可以递增。请注意,
字符串
是不可变的。请正确设置代码格式。您可以发布示例字符串输入和所需输出吗?字符串不是数值。不能“递增”字符串。让它成为一个整数,这样你就可以递增请注意,
字符串
是不可变的。请正确格式化你的代码,你可以发布示例字符串输入和你想要的输出吗?我没有这么说,你这么说是什么意思:“ArrayList包含一个对象列表,所以你不能用类型字符串遍历它。”??他还明确指定他的arraylist保存字符串实例。它保存一个对象列表并不意味着它只能包含对象,但我可以看到混淆。在这个问题上,它足够像我一样迭代,因为arraylist保存对字符串对象的引用,除非我误解了这个问题。我没有这么说。你这么说是什么意思:“ArrayList包含一个对象列表,所以你不能用类型字符串遍历它。”??他还明确指定arraylist保存字符串实例。它保存一个对象列表并不意味着它只能包含对象,但我可以看到混淆。在这个问题中,正如我所做的那样进行迭代就足够了,因为arraylist保存了对字符串对象的引用,除非我误解了这个问题。