Java Fundamentals 14

Source: Internet
Author: User

1 Object Array
    • Example:
 PackageCom.xuweiwei;/*** Student Class*/ Public classStudent {PrivateString name; PrivateInteger age;  PublicStudent () {} PublicStudent (String name, Integer age) { This. Name =name;  This. Age =Age ; }     PublicString GetName () {returnname; }     Public voidsetName (String name) { This. Name =name; }     PublicInteger getage () {returnAge ; }     Public voidsetage (Integer age) { This. Age =Age ; } @Override PublicString toString () {return"student{" + "name=" + name + ' \ ' + ", age=" + Age + '} '; }}
 PackageCom.xuweiwei;/*** I have 5 students, please store the information of these 5 students in an array, and iterate through the array to get information about each student*/ Public classObjectarraydemo { Public Static voidMain (string[] args) {Student S1=NewStudent ("A", 8); Student S2=NewStudent ("B", 9); Student S3=NewStudent ("C", 10); Student S4=NewStudent ("D", 11); Student S5=NewStudent ("E", 12); Student[] Students={S1,S2,S3,S4,S5};  for(inti = 0; i < students.length; i++) {Student s=Students[i];        System.out.println (s); }    }}

2 Overview of Integrated 2.1 2.1.1 Why does the collection appear?
    • Object-oriented language is the embodiment of things in the form of objects, so in order to facilitate the operation of multiple objects, Java provides a collection of classes.
What is the difference between a 2.1.2 array and a collection class in the same container?
    • Arrays can also store objects, but the lengths are fixed, and the length of the collection can vary.
    • The base type of data can be stored in an array, but the collection can only store objects.
Characteristics of 2.1.3 Collection class
    • The ① collection can store only objects.
    • The length of the ② collection can vary.
    • The ③ collection can store different types of objects.

Java Fundamentals 14

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.