gpt4 book ai didi

java - 如何将 arraylist 字符串值加一

转载 作者:行者123 更新时间:2023-12-01 07:47:44 24 4
gpt4 key购买 nike

有两个 for 循环,我想从内部 for 循环将字符串类型的数组列表值加一。我怎样才能做到这一点?

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<String> location; //Location and distanceInMiles are ArrayList<String> type and i have store some value into it.
ArrayList<String> distanceInMiles;
for(String strloc : location){
ArrayList<String> clone = (ArrayList<String>) distanceInMiles.clone();
distanceInMiles.clear();
for(String strDist : clone){
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
distanceInMiles.add(Integer.parseInt(strDist) + 1 + "");
break;
}
}

希望对你有帮助!

关于java - 如何将 arraylist 字符串值加一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47990219/

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