2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
Sequentia mensa est structura linearis quae unitas reposita cum continua corporis inscriptione utitur ad elementorum notitias reponendas in ordine. Perficere additionem, deletionem, recognitionem et modificationem notitiarum in ordine.
Tabulae lineares generaliter comprehendunt modos sequentes;
public class { MyArrayList
private int[] array;
pri- int magnitudine;
// Quod default constructione modum spatium per default collocat
SeqList(){ }
// constitue underlying facultatem ex ordine mensa ad certum facultatem
SeqList(int initcapacitas){ }
// Adde nova elementa, defaltam in fine ordinatae adduntur
vacuum publicum add(int data) { }
// Add elementum at pos positione
vacuum publicum add(int pos, int data) { }
// Utrum elementum contineatur
public boolean continet (int toFind) verum {reditu; }
// Reperio loco respondentem ad elementum
public int indexOf (int toFind) { return -1 ; }
// Get elementum ad pos positione
public int get (int pos) { return -1 ; }
// constitue elementum ante pos loco ad valorem
publicum vacuum (int pos, int value) { }
// Delere primum eventum keyword clavis
publicum inane remove(int toRemove) { }
// Get longitudinem sequentia mensam
public int size() { return 0; }
// Serena ordinem mensam
publicum inane clarum() { }
// Print sequence table
publicum inane ostentationem() { }
}
Deinde efficiendum tabulam sequentiam generis int secundum modum superius:
- import java.util.Arrays;
- public class MyArrayList {
- private int[] elem;
- private int usedSize;
- private static final int DEFAULT_SIZE = 10;
- public MyArrayList(){
- elem = new int[DEFAULT_SIZE];
- }
- public MyArrayList(int initCapacity){
- elem = new int[initCapacity];
- }
-
- private boolean checkCapacity(){
- if(this.usedSize == elem.length){
- return true;
- }
- return false;
- }
-
- public void display(){
- for (int i = 0; i < this.usedSize; i++) {
- System.out.print(this.elem[i] + " ");
- }
- }
- public void add(int data){
- if(checkCapacity()){
- this.elem = Arrays.copyOf(this.elem,2*elem.length);
- }
- this.elem[this.usedSize] = data;
- this.usedSize++;
- return;
- }
- public void add(int pos,int data){
- if(pos > this.usedSize || pos < 0){
- throw new PosOutOfBoundsException("插入位置错误!");
- }
- if(checkCapacity()){
- this.elem = Arrays.copyOf(this.elem,2*elem.length);
- }
- for (int i = this.usedSize - 1; i >=pos ; i--) {
- elem[i+1] = elem[i];
- }
- this.elem[pos] = data;
- this.usedSize++;
- return;
- }
-
- public boolean contains(int data){
- for (int i = 0; i < this.usedSize; i++) {
- if(this.elem[i] == data){
- return true;
- }
- }
- return false;
- }
-
- public int indexof(int data){
- for (int i = 0; i < this.usedSize; i++) {
- if(this.elem[i] == data){
- return i;
- }
- }
- return -1;
- }
- public int get(int pos){
- if(pos >= this.usedSize || pos < 0){
- throw new PosOutOfBoundsException("输入的位置错误!");
- }
- return this.elem[pos];
- }
- public void set(int pos,int data){
- if(pos >= this.usedSize || pos < 0){
- throw new PosOutOfBoundsException("输入的位置错误!");
- }
- this.elem[pos] = data;
- }
- public int size(){
- return this.usedSize;
- }
- public void remove(int data){
- if(this.contains(data)){
- int pos = this.indexof(data);
- for (int i = pos; i < this.usedSize - 1; i++) {
- this.elem[pos] = this.elem[pos+1];
- }
- this.usedSize--;
- }else{
- throw new PosOutOfBoundsException("没有该元素");
- }
- }
- public void clear(){
- this.usedSize = 0;
- return;
- }
- }
In compage collectionis, ArrayList genus est ordinarium quod instrumenti indices instrumenti conficit.
Constructor methodi in ArrayList:
ArrayList();
ArrayList (Collectio<? extends E> c);
ArrayList(int initialCapacity);
Exemplum codicis:
- public class Test {
- public static void main(String[] args) {
- List<Integer> list1 = new ArrayList<>();//无参构造
- List<Integer> list2 = new ArrayList<>(10);//指定容量
- list2.add(1);
- list2.add(2);
- list2.add(3);
- List<Integer> list3 = new ArrayList<>(list2);//利用其他 Collection 构建 ArrayList
- }
- }
- public class Test {
- public static void main(String[] args) {
- List<Integer> list = new ArrayList<>();//无参构造
- list.add(1);
- list.add(2);
- list.add(3);
- System.out.println(list);
- }
- }
- public class Test {
- public static void main(String[] args) {
- List<Integer> list = new ArrayList<>();
- list.add(1);
- list.add(2);
- list.add(3);
- list.add(1,4);
- System.out.println(list);
- }
- }
- public class Test {
- public static void main(String[] args) {
- List<Integer> list1 = new ArrayList<>();
- list1.add(4);
- list1.add(5);
- list1.add(6);
- List<Integer> list = new ArrayList<>();
- list.add(1);
- list.add(2);
- list.add(3);
- list.addAll(list1);
- System.out.println(list);
- }
- }
- public class Test {
- public static void main(String[] args) {
- List<Integer> list = new ArrayList<>();
- list.add(1);
- list.add(2);
- list.add(3);
- list.remove(1);
- System.out.println(list);
- }
- }
- public class Test {
- public static void main(String[] args) {
- List<Integer> list = new ArrayList<>();
- list.add(1);
- list.add(2);
- list.add(3);
- list.remove(new Integer(2));
- System.out.println(list);
- }
- }
- public class Test {
- public static void main(String[] args) {
- List<Integer> list = new ArrayList<>();
- list.add(1);
- list.add(2);
- list.add(3);
- System.out.println(list.get(1));
- }
- }
- public class Test {
- public static void main(String[] args) {
- List<Integer> list = new ArrayList<>();
- list.add(1);
- list.add(2);
- list.add(3);
- list.set(1,4);
- System.out.println(list);
- }
- }
- public class Test {
- public static void main(String[] args) {
- List<Integer> list = new ArrayList<>();
- list.add(1);
- list.add(2);
- list.add(3);
- list.clear();
- System.out.println(list);
- }
- }
- public class Test {
- public static void main(String[] args) {
- List<Integer> list = new ArrayList<>();
- list.add(1);
- list.add(2);
- list.add(3);
- System.out.println(list.contains(2));
- System.out.println(list.contains(4));
- }
- }
- public class Test {
- public static void main(String[] args) {
- List<Integer> list = new ArrayList<>();
- list.add(1);
- list.add(2);
- list.add(3);
- list.add(1);
- System.out.println(list.indexOf(1));
- }
- }
- public class Test {
- public static void main(String[] args) {
- List<Integer> list = new ArrayList<>();
- list.add(1);
- list.add(2);
- list.add(3);
- list.add(1);
- System.out.println(list.lastIndexOf(1));
- }
- }
- public class Test {
- public static void main(String[] args) {
- List<Integer> list = new ArrayList<>();
- list.add(1);
- list.add(2);
- list.add(3);
- System.out.println(list.subList(0,2));
- }
- }
ArrayList peragi potest tribus modis: ansa + subscript, ansa aucta et iteratores utens
- public class Test {
- public static void main(String[] args) {
- List<Integer> list = new ArrayList<>();
- list.add(1);
- list.add(2);
- list.add(3);
- //使用fori遍历
- for (int i = 0; i < list.size(); i++) {
- System.out.print(list.get(i));
- }
- System.out.println();
- //使用foreach遍历
- for(Integer integer:list){
- System.out.print(integer);
- }
- System.out.println();
- //使用迭代器遍历
- Iterator<Integer> it = list.listIterator();
- while(it.hasNext()){
- System.out.print(it.next());
- }
- }
- }
operatio effectus;
Usus missionis ArrayList
Constrata cinematographica versas chartulas lusorias passim et eas tribus hominibus cum quinque schedulis distribuas.
Locus originalis codicis algorithmi:
Descriptio topic:
Codicis:
- public class Test {
- public static List<List<Integer>> generate(int numRows) {
- List<List<Integer>> list = new LinkedList<>();
- for (int i = 0; i < numRows; i++) {
- List<Integer> row = new LinkedList<>();
- for (int j = 0; j < i + 1; j++) {
- if (j == 0 || i == j) {
- row.add(1);
- } else {
- row.add(list.get(i - 1).get(j - 1) + list.get(i - 1).get(j));
- }
- }
- list.add(row);
- }
- return list;
- }
-
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int numRows = scanner.nextInt();
- List<List<Integer>> list = generate(numRows);
- for (int i = 0; i < numRows; i++) {
- for (int j = 0; j < i + 1; j++) {
- System.out.print(list.get(i).get(j) + " ");
- }
- System.out.println();
- }
- }
- }
Consequuntur cursus lacinia purus: