Giới thiệu cách cài đặt ArayList trong ngôn ngữ lập trình Java
Giới thiệu cách cài đặt ArayList trong ngôn ngữ lập trình Java
package arrayListDemo;
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 input() {
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());
}
}
class list {
ArrayList<student> list = new ArrayList<student>();
void input() {
student st[] = new student[3];
for (int i = 0; i < 3; i++) {
st[i] = new student();
st[i].input();
list.add(st[i]);
}
}
void output() {
for (int i = 0; i < list.size(); i++) {
list.get(i).output();
}
}
void delete(int id) {
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getId() == id) {
list.remove(i);
}
}
}
void update(int id) {
for(int i=0;i<list.size();i++) {
if(list.get(i).getId()==id) {
list.get(i).setName("Khoa");
list.set(i,list.get(i));
}
}
}
void sort() {
}
}
public class demo {
public static void main(String[] args) {
list l = new list();
l.input();
l.output();
l.update(1);
l.output();
}
}
Trương Đình Huy
- 6 công nghệ trong điện thoại bạn dùng mỗi ngày (mà ít khi biết nó hoạt động thế nào)
- DBT là gì? Tìm hiểu Công cụ Transform trong Data Engineering
- Software Testing - Common Testing Techniques (P1)
- Báo Cáo Chuyên Sâu Về Khung Pháp Lý V Của Hội Đồng Đạo Đức Y Sinh Học Đối Với Nghiên Cứu Thu Thập Tín Hiệu Điện Não Bằng Nền Tảng OpenBCI Tại Việt Nam

