JAVA小白的入门笔记—ArrayList

一.ArrayList

动态可伸缩数组,长度可变数组

二.形式

ArraryListstringList = new ArrayList();
(数据类)

关于ArrayList的几个重点JAVA小白的入门笔记—ArrayList_第1张图片

next nextLine nex int 的区别
next:另起一行开始读取,以空格,换行,制表符结束
nextLine:输入时执行接着上一行的代码继续读取
next int :不能换行,跟着输入的东西后面进行读取
附照片
JAVA小白的入门笔记—ArrayList_第2张图片
JAVA小白的入门笔记—ArrayList_第3张图片

依旧附上一段JAVA小白的ArrayList代码

“`
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());
    }
}

}

你可能感兴趣的:(JAVA小白的入门笔记—ArrayList)