码迷,mamicode.com
首页 > 其他好文 > 详细

key Value

时间:2018-06-20 16:36:53      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:分享   rri   ext.get   ng2   null   stat   分享图片   add   move   

key 存值的编号

value 存放的数据

技术分享图片

看来key 和value 可以为null~

 

 

 

技术分享图片
public class Dog {
private int id;
private String name;

@Override
public String toString() {
return "Dog{" +
"id=" + id +
", name=‘" + name + ‘\‘‘ +
‘}‘;
}

public Dog() {
}

public Dog(int id, String name) {
this.id = id;
this.name = name;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public static void main(String[] args) {
Dog dog = new Dog();
System.out.println(dog);
}
}
技术分享图片

 

 

 

技术分享图片
import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;


public class ArrayListTest {
public static void main(String[] args) {

ArrayList arrayList = new ArrayList();
arrayList.add(1);
arrayList.add(1);
arrayList.add(1);
arrayList.add(1);
arrayList.add(1);
System.out.println("arrayList.size() = " + arrayList.size());
System.out.println("arrayList.iterator() = " + arrayList.iterator());

List list = new ArrayList();
Dog dog1 = new Dog(1, "wang1");
Dog dog2 = new Dog(2, "wang2");
Dog dog3 = new Dog(3, "wang3");
Dog dog4 = new Dog(4, "wang4");
Dog dog5 = new Dog(5, "wang5");
list.add(dog1);
list.add(dog2);
list.add(dog3);
list.add(dog4);
list.add(dog5);

System.out.println("list.size() = " + list.size());

System.out.println("list.get(3) = " + list.get(2));

System.out.println("list.remove(5) = " + list.remove(3));

System.out.println("list.contains(wang2) = " + list.contains(dog2));

list.add(0, new Dog(6, "wang6"));

list.add(1, new Dog(9, "wang9"));

for (int i = 0; i < list.size(); i++) {
Dog dog = (Dog) list.get(i);
System.out.println("dog.getName() = " + dog.getName());
}
System.out.println("*****************我是华丽的分界线*********************");
Object[] array = list.toArray();
for (int i = 0; i < array.length; i++) {
Dog dog = (Dog) array[i];
System.out.println("dog.getName() = " + dog.getName());
}
System.out.println("*****************我是华丽的分界线*********************");
for (Object a : list) {
Dog dog = (Dog) a;
System.out.println("dog.getName() = " + dog.getName());
}
System.out.println("*****************我是华丽的分界线*********************");
Iterator iterator = list.iterator();
while (iterator.hasNext()) {
Dog next = (Dog) iterator.next();
System.out.println("next.getName() = " + next.getName());
}
System.out.println("*****************我是华丽的分界线*********************");
list.clear();//清空整个集合=。= 一般人我不告诉他 到时候清空了 还怪我 (ˉ▽ ̄~) 切~~
System.out.println("*****************我是华丽的分界线*********************");
System.out.println("list.isEmpty() = " + list.isEmpty());
System.out.println("list.size() = " + list.size());

}
}
技术分享图片

 

 

 

技术分享图片

技术分享图片

 

 

 

技术分享图片

技术分享图片

 

 

 

技术分享图片

技术分享图片

 

 

 

技术分享图片

技术分享图片

 

key Value

标签:分享   rri   ext.get   ng2   null   stat   分享图片   add   move   

原文地址:https://www.cnblogs.com/yunfeioliver/p/9204297.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!