网站开发外包价格,设计手机网站建设,pc端移动端网站开发,优享 wordpress我们用java进行Android开发过程中#xff0c;经常会用到for循环#xff0c;在Kotlin中也会经常用到#xff0c;但是在最近使用Kotlin中我发现#xff0c;在java中使用for循环不会有什么问题#xff0c;但是在Kotlin中会出现问题#xff0c;就是循环出出来的结果不一样经常会用到for循环在Kotlin中也会经常用到但是在最近使用Kotlin中我发现在java中使用for循环不会有什么问题但是在Kotlin中会出现问题就是循环出出来的结果不一样到目前还未找到合适的解决方法希望通过记录这个问题以便以后遇到类似问题能够方便查找。下面具体具体说明一下
在JAVA中的使用 ListDouble pos new ArrayList();for (int k1 0; k1 poslists.size() - 1; k1 k1 2) {String a1 poslists.get(k1);String a2 poslists.get(k1 1);int b1 Integer.parseInt(a1.substring(0, a1.lastIndexOf(_)));int b2 Integer.parseInt(a2.substring(0, a2.lastIndexOf(_)));for (int i b1; i b2; i) {pos.add(Double.parseDouble(a1.substring(a1.lastIndexOf(_) 1)));}}
其中poslists是一个ListString 其中添加的数据类型是0_5,332_7等等pos获取的是5,7等等在Java中就完全没问题但是在kotlin中获取的数据就会出现少数据主要体现在每次变换体位比如5-7就会多出来一个值
下面是Kotlin中对应的这段代码
var k1 0
while (k1 poslists.size - 1) {val a1: String poslists.get(k1)val a2: String poslists.get(k1 1)val b1 a1.substring(0, a1.lastIndexOf(_)).toInt()val b2 a2.substring(0, a2.lastIndexOf(_)).toInt()for (i in b1 until b2) {pos.add(a1.substring(a1.lastIndexOf(_) 1).toDouble())}k1 k1 2
}
希望有知道的网友能够帮忙看一下。