ArrayList class Example 1

Source: Internet
Author: User

ArrayList Class Example 2

Import java.util.ArrayList;



public class ArrayListDemo2 {

Into

public static void Main (string[] args) {

arraylist<integer> A1 = new arraylist<integer> (); To create an empty ArrayList object

for (int i=0; i<10;i++) {

Integer a2 = new Integer (i);//Create a wrapper object of an integral type

A1.add (A2); Put this object into the ArrayList

}

Take out

System.out.println ("Elements in the array");

for (int i=0;i<a1.size (); i++) {

Integer a3 = (integer) (A1.get (i));//Get the element indexed as I in ArrayList

SYSTEM.OUT.PRINTLN (A3);

}

System.out.println ("------------");

A1.clear (); Empty

System.out.println ("The case after the array is emptied");

System.out.println ("The length of the array is" +a1.size ());

if (A1.isempty ()) {//Determine if empty

SYSTEM.OUT.PRINTLN ("Array is now empty");

}else{

SYSTEM.OUT.PRINTLN ("Array is now not empty");

}

}


}


This article is from the "Basic Java Primer Notes" blog, declined reprint!

ArrayList class Example 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.