List<T>对象:对象里面的元素属性包含List<T>(只有一个对象);
对象List<T>:List<T>里面的数据是对象类型(可以有多组对象,但必须是同一个类型);
测试案例:
Book类:
import java.util.List;
public class Book {
private ListString> name;
private ListInteger> price;
public ListString>服务器托管网 getName() {
return name;
}
public void setName(ListString> name) {
this.name = name;
}
public ListInteger> getPrice() {
return price;
}
public void setPrice(ListInteger> price) {
this.price = price;
}
public Book(ListString> name, ListInteger> price) {
super();
this.name = name;
this.price = price;
}
public Book() {
super();
}
}
Student类:
public class Student {
private String name;
private int age;
private String address;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public Student(String name, int age, String address) {
super();
this.name = name;
this.age = age;
this.address = address;
}
public Student() {
super();
}
}
测试Demo : (重点)
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public cla服务器托管网ss day19 {
public static void main(String[] args) {
// List<T>对象:对象里面的元素属性包含List<T>(只有一个对象);
ListString> list = new ArrayList>();
Book b = new Book();
ListString> nameList = Arrays.asList("语文","数学","英语");
ListInteger> priceList = Arrays.asList(29,39,49);
b.setName(nameList);
b.setPrice(priceList);
ListString> nameList2 = b.getName();
for(String s:nameList2) {
System.out.println("List<T>对象name:"+s);
}
ListInteger> priceList2 = b.getPrice();
for(Integer s:priceList2) {
System.out.println("List<T>对象price:"+s);
}
System.out.println("-------------------");
// 对象List<T>:List<T>里面的数据是对象类型(可以有多组对象,但必须是同一个类型);
ListStudent> list2 = new ArrayList>();
list2.add(new Student("小婷",22,"宝鸡"));
list2.add(new Student("小霞",24,"西安"));
list2.add(new Student("小桐",26,"汉中"));
System.out.println("对象List<T>");
for(Student s : list2) {
Student st = s;
System.out.println("name:"+st.getName()+"--"+"age:"+st.getAge()+"--"+"address:"+st.getAddress());
}
}
}
测试输出:
List<T>对象name:语文
List<T>对象name:数学
List<T>对象name:英语
List<T>对象price:29
List<T>对象price:39
List<T>对象price:49
-------------------
对象List<T>
name:小婷--age:22--address:宝鸡
name:小霞--age:24--address:西安
name:小桐--age:26--address:汉中
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
为啥争吵,吵什么? “你到底在说什么啊,我K8s的ecs节点要访问clb的地址不通和本地网卡有什么关系…” 气愤语气都从电话那头传了过来,这时电话两端都沉默了。过了好一会传来地铁小姐姐甜美的播报声打断了刚刚的沉寂「乘坐地铁必须全程佩戴口罩,下一站西湖文化广…