Android crash记录
程序员文章站
2022-04-15 18:37:03
...
CopyOnWriteArrayList arrayList;
HashMap<Integer,String> map = new HashMap<Integer,String>();
public void operationHashMap(){
for(int i=0;i<10;i++){
map.put(i,"value"+i);
}
// 错误删除map的方式
for (Map.Entry<Integer,String> entry:map.entrySet()){
Integer key = entry.getKey();
if (key % 2 == 0){
map.remove(key);
}
}
// 正确删除map方式
List delList = new ArrayList();
for (Map.Entry<Integer,String> entry:map.entrySet()){
Integer key = entry.getKey();
if (key % 2 == 0){
delList.add(key);
}
}
for (int i=0;i<delList.size();i++){
map.remove(delList.get(i));
}
}
Comparator comparator;
static ArrayList<Integer> list = new ArrayList<Integer>();
void testScenario2(){
for (int i=0;i<100;i++){
list.add(i);
}
Thread1 thread1 = new Thread1();
thread1.start();
Thread2 thread2 = new Thread2();
thread2.start();
}
class Thread1 extends Thread{
@Override
public void run() {
while (true){
Iterator<Integer> iterator = list.iterator();
while (iterator.hasNext()){
System.out.println(iterator.hasNext());
}
}
}
}
class Thread2 extends Thread{
@Override
public void run() {
while (true){
for (int j=101;j<200;j++){
list.add(j);
}
}
}
}