"Head First Java reading notes" (vi) Understanding Java APIs

Source: Internet
Author: User

The fifth chapter uses the Java function library ArrayList
  • add(Object elem)
  • remove(int index)
  • remove(Object elem)
  • contains(Object elem)
  • isEmpty()
  • indexOf(Object elem)
  • size()
  • get(int index)
The difference between a ArrayList and a general array

ArrayList
ArrayList myList = new ArrayList ();

String  a  = new String("whoohoo");myList.add(a);String b = new String("Frog");myList.add(b);int theSize = myList.size();Object o = myList.get(1);myList.remove(1);

General Array

Boolean isIn = Mylist.contains (b); string[] myList = new string[2]; String a = new string ("Whoohoo"); mylist[0]=a; String b = new String ("Frog"); Mylist[1]=b;int thesize = Mylist.length;    String o = Mylist[1];mylist[1]=null;boolean isIn = false;for (string item:mylist) {if (B.equals (item)) {IsIn = true;    Break }}
    • When created in a generic array, the size must be determined, but ArrayList only needs to create objects of this type at the row. You do not need to specify a size.
    • Location must be specified when storing objects to a generic array
Q&a

Will using import make the program larger, and will the compilation process wrap the package or class in?
Using import only saves you the package name in front of each class, and the program does not become larger and slower because of the import.

Why import into a string class or system class is not required
Remember that Java.lang is a pre-quoted package.

Head First Java reading notes (vi) Understanding the Java API

Related Article

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.