ArrayList用法示例

2021-05-26 20:34:58 字數 1023 閱讀 8808

(一) public class student implements comparable

public string getname()

public int compareto(student stu)

public string tostring()

}(二)

public class add

//向array中新增student的物件

public void add(student stu)

//從array中移除指定姓名的student物件

public void remove(string name)

catch (interruptedexception e)

system.out.println("刪除成功!");

break;

}else

catch (interruptedexception e) }}

}//把array中的資料轉成student的陣列,用arrays.sort()排序後輸出(排序的前提是student類中實現了comparable介面)

public void showall()

);arrays.sort(st);

for(student stu:st)}}

(三)package org.hwh.jihe2;

public class test

;string name=;

int score1=;

int score2=;

int score3=;

student stu=new student[5];

for(int i=0;i<5;i++)

ad.remove("狗屎");

try catch (interruptedexception e)

system.out.println("正在排序輸出....");

try catch (interruptedexception e)

ad.showall();}}

ArrayList用法 (經典)

system.collections.arraylist類是乙個特殊的陣列。通過新增和刪除元素,就可以動態改變陣列的長度。一 優點 1。支援自動改變大小的功能 2。可以靈活的插入元素 3。可以靈活的刪除元素 二 侷限性 跟一般的陣列比起來,速度上差些 三 新增元素 1 publicvirtualin...

ArrayList類的用法

靈活的設定陣列的大小 int32 values int32 list.toarray typeof int32 返回arraylist包含的陣列 這是乙個簡單的例子,雖然沒有包含arraylist所有的方法,但是可以反映出arraylist最常用的用法 用指定的大小來初始化內部的陣列 如果使用arr...

Mysql limit offset 用法示例

mysql limit offset示例 例1,假設資料庫表student存在13條資料。示例 語句1 select from student limit 9,4 語句2 slect from student limit 4 offset 9 語句1和2均返回表student的第10 11 12 1...