Minh họa cách sử dụng ArrayList
Đây là ví dụ minh họa cách sử dụng ArrayList trong Java. Trong ví dụ này, mô tả và hướng dẫn cách cài đặt ArrayList dành cho người mới bắt đầu học Java cơ bản.
package demoArrayList1;
import java.util.*;
class student {
int id;
String 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;
}
void intput() {
Scanner objSc = new Scanner(System.in);
System.out.print("id:");
this.setId(objSc.nextInt());
objSc.nextLine();
System.out.print("Name:");
this.setName(objSc.nextLine());
}
void output() {
System.out.println("id " + " " + this.getId() + "Name " + " " + this.getName());
}
}
public class demo {
public static void main(String[] args) {
ArrayList<student> list = new ArrayList<student>();
student st[] = new student[3];
for (int i = 0; i < st.length; i++) {
st[i] = new student();
st[i].intput();
list.add(st[i]);
}
for (int i = 0; i < list.size(); i++) {
list.get(i).output();
}
}
}
Trương Đình Huy
- So sánh hệ thống tài khoản kế toán trong Thông tư 99/2025/TT-BTC và Thông tư 200/2014/TT-BTC
- Common Pitfalls in TOEIC Preparation and How Strategic Learning Improves Test Performance
- Singapore’s First Multi-Storey 3D-Printed House
- 3D Concrete printing Technology
- Giới thiệu 8 đặc điểm của High Performance Team

