ArrayList浅拷贝clone,Kotlin
import kotlin.collections.ArrayList
fun main() {
var list = ArrayList<MyData>()
for (i in 0..<3) {
list.add(MyData(i, 0))
}
//浅拷贝list到copyList
var copyList = list.clone()
println(list)
println(copyList)
println("---")
//改变list的值,然后观察copyList的值变化。
list.forEachIndexed { index, myData ->
myData.pos = index
}
list.removeAt(list.size - 1)
println(list)
println(copyList) //copyList里面的对象MyData的值和list一致,如果该元素存在。
}
data class MyData(var index: Int, var pos: Int)
[MyData(index=0, pos=0), MyData(index=1, pos=0), MyData(index=2, pos=0)]
[MyData(index=0, pos=0), MyData(index=1, pos=0), MyData(index=2, pos=0)]
---
[MyData(index=0, pos=0), MyData(index=1, pos=1)]
[MyData(index=0, pos=0), MyData(index=1, pos=1), MyData(index=2, pos=2)]
Java ConcurrentLinkedQueue队列线程安全操作_zhangphil的博客-CSDN博客Java ConcurrentLinkedQueue队列线程安全操作代码示例:package async;import java.util.ArrayList;import java.util.List;import java.util.Queue;import java.util.concurrent.ConcurrentLinkedQueue;/** * * 线程安全队https://blog.csdn.net/zhangphil/article/details/65936066
Java的Vector,Stack,ArrayList,LinkedList异同_zhangphil的博客-CSDN博客Java的Vector,Stack,ArrayList,LinkedList异同Collection的实现子类型是什么,它都支持iterator()函数,该函数返回一个迭代器,该迭代器即可遍历访问Collection中每一个元素。Collection派生出来的两个接口类List和Set。List是有序的Collection。和Set不同,List允许有相同元素。List接口实现类...https://blog.csdn.net/zhangphil/article/details/91822423
Java反转一个List或ArrayList_zhangphil的博客-CSDN博客package demo;import java.util.ArrayList;import java.util.Collections;/** * * 反转一个List,关键是使用Collections工具类 * * @author Phil * */public class Demo {public static void main(String[] args)https://blog.csdn.net/zhangphil/article/details/54406817