福工刘德华
2017-11-05 20:41
我认为正确的传参方式:
public void testStudentsort()
{
List<student>studentlist= new ArrayList<student>();
studentlist.add(new student("1","小明"));
studentlist.add(new student("2","小红"));
studentlist.add(new student("3","小绿"));
for (student student : studentlist) {
System.out.println("学生"+student.name);
}
}
老师添加学生类的代码
public void testStudentsort()
{
List<student>studentlist= new ArrayList<student>();
studentlist.add(new student(1+"","小明"));
studentlist.add(new student(2+"","小红"));
studentlist.add(new student(3+"","小绿"));
for (student student : studentlist) {
System.out.println("学生"+student.name);
}
}
studentlist.add(new student(1+"","小明");
(1+"")这就是一个字符串啊,数字+""就转成字符串了,等同于"1"。
int转String :
int i =1;
String is =i+"";
int i =1;
String is =i.valueOf(i);
int + String 等于 String
Java入门第三季
409792 学习 · 4340 问题
相似问题