动态可伸缩数组,长度可变数组
ArraryListstringList = new ArrayList();
(数据类)
next nextLine nex int 的区别
next:另起一行开始读取,以空格,换行,制表符结束
nextLine:输入时执行接着上一行的代码继续读取
next int :不能换行,跟着输入的东西后面进行读取
附照片
“`
package com.lenovo.www.entity;
import java.util.ArrayList;
public class CunCu {
static ArrayListlist = new ArrayList<>();
public static void main(String[] args) {
// TODO Auto-generated method stub
list.add("Amily,40");
list.add("Frank");
list.add("Michael");
list.add("Miami");
for(int i=0;i
}
}
`package com.lenovo.www.entity;
import java.util.ArrayList;
import javax.rmi.CORBA.Stub;
/*
* 学生测试类
*/
public class test {
public static void main(String[] args) {
ArrayList studentList = new ArrayList<>();
Student s1 = new Student("小紅", "二年級一班", 6);
Student s2 = new Student("小白", "二年級二班", 6);
Student s3 = new Student("小黑", "二年級三班", 6);
Student s4 = new Student("小蓝", "二年級四班", 6);
Student s5 = new Student("小灰", "二年級五班", 6);
Student s6 = new Student("小绿", "二年級六班", 6);
studentList.add(s1);
studentList.add(s2);
studentList.add(s3);
studentList.add(s4);
studentList.add(s5);
studentList.add(s6);
for (Student stu : studentList) {
System.out.println("姓名" + stu.getName() + ",年级:" + stu.getClassName() + " 年龄: " + stu.getAge());
}
studentList.remove(studentList.size() - 2);
System.out.println();
for (int i = 0; i < studentList.size(); i++) {
Student s = studentList.get(i);
System.out.println("姓名" + s.getName() + ",年级:" + s.getClassName() + " 年龄: " + s.getAge());
}
}
}