inotgo.com

This video is interpretive , So I hope you have read the content of this knowledge point , And after writing the corresponding code , Watch with questions , Only in this way can we gain more . It is not recommended to watch the video at the beginning



3 branch 7 second
This video uses html5 Play mode , If it cannot be played normally , Please upgrade your browser to the latest version , Recommend Firefox ,chrome,360 browser . If thunderbolt is installed , Play the video and show the direct download status , Please adjust Thunderbolt system settings - Basic settings - Start - Monitor all browsers ( Remove this option ). chrome of Video download Plug-in will affect playback , as IDM etc. , Please close or switch other browsers



Example 1 : Limitations of using arrays   
Example 2 : ArrayList Storage object   

Example 1 :

Limitations of using arrays

edit top fracture
If you want to store multiple objects , You can use arrays , But arrays have limitations
For example The declaration length is 10 Array of
Unused arrays are wasted
exceed 10 Number of , I can't let go
package collection; import charactor.Hero; public class TestCollection { public static void main(String[] args) { // Limitations of arrays Hero heros[] = new Hero[10]; // The declaration length is 10 Array of // Unused arrays are wasted // exceed 10 Number of , I can't let go heros[0] = new Hero(" Galen "); // If you can't put it down, you have to report an error heros[20] = new Hero(" Timo "); } }
package charactor; public class Hero { public String name; public float hp; public int damage; public Hero() { } // Add an initialization name The construction method of public Hero(String name) { this.name = name; } // rewrite toString method public String toString() { return name; } }
To address the limitations of arrays , Introduce the concept of container class . The most common container class is
ArrayList
The capacity of the container "capacity" As the number of objects increases , Automatic growth
Just keep adding heroes to the container , Don't worry about the boundary of the array .
package collection; import java.util.ArrayList; import charactor.Hero; public class TestCollection { @SuppressWarnings("rawtypes") public static void main(String[] args) { // Container class ArrayList, Used to store objects ArrayList heros = new ArrayList(); heros.add( new Hero(" Galen ")); System.out.println(heros.size()); // The capacity of the container "capacity" As the number of objects increases , Automatic growth // Just keep adding heroes to the container , Don't worry about the boundary of the array . heros.add( new Hero(" Timo ")); System.out.println(heros.size()); } }


The official account of programming , Follow and get the latest tutorials and promotions in real time , thank you .


Q & A area    
2020-08-09 Java aggregate In combination with JDK Notes recorded by the source code , I hope I can help you
jimisun

Note address https://www.focusnote.cn/focus/ff80808173a2e0700173cedbb996001b.html




2 One answer

ahead
Answer time :2021-03-28
hxd The notes hang up

pentacf
Answer time :2021-03-03
The notes hang up , brother



The answer has been submitted successfully , Auditing . Please My answer Check the answer record at , thank you
answer Or code please Fill in at least one , If you have a problem , Please ask again , Otherwise, the webmaster may not see




2020-06-27 You can also understand directly with this code arraylist
1|1|1|1




Look at the code
package framework;

import java.util.ArrayList;


public class arrayList {
    public static void main(String[] args) {
        // Container class ArrayList, Used to store objects 
        ArrayList heros = new ArrayList();
        System.out.println(heros.size());
        heros.add(" Galen ");
        System.out.println(heros.size());
        // The capacity of the container "capacity" As the number of objects increases , Automatic growth 
        // Just keep adding heroes to the container , Don't worry about the boundary of the array .
        heros.add( " Timo ");
        System.out.println(heros.size());
    }

}
 
               


2 One answer

stone520
Answer time :2020-10-16
The string itself is an object , It is not a basic data type , You put two strings , It's actually two string objects

No pulp, all waves
Answer time :2020-09-11
This one doesn't add new Hero() If not, the object is not stored , It's a string



The answer has been submitted successfully , Auditing . Please My answer Check the answer record at , thank you
answer Or code please Fill in at least one , If you have a problem , Please ask again , Otherwise, the webmaster may not see





2020-03-31 Why output the whole List When I was Don't rewrite tostring() Method will output the address of the object Instead of attribute values
2019-04-03 list Add questions
2019-03-25 What's going on , Prompt missing class How to deal with it, big guys


Too many questions , Page rendering is too slow , To speed up rendering , Only a few questions are displayed on this page at most . also 8 Previous questions , please Click to view

Please... Before asking questions land
The question has been submitted successfully , Auditing . Please My question Check the question record at , thank you
about JAVA Intermediate - Collection framework - The difference from arrays Your questions

Try to provide Screenshot code and Abnormal information , Help to analyze and solve problems . You can also enter this station QQ Group communication : 496725845
Ask questions and try to provide complete code , Environment description , The more conducive to the recurrence of the problem , The faster your question can be answered .
Have questions about the code in the tutorial , Please provide which step , Which line is in doubt , This makes it easy to quickly locate the problem , Improve the speed at which questions are answered
In the thousands of questions that already exist , A considerable proportion , Because of the use of and webmaster Different versions of the development environment Resulting in , For example jdk, eclpise, idea, mysql,tomcat Wait, the version of the software is inconsistent .
Please use the same version as the webmaster , You can save yourself a lot of learning time . The webmaster sorted out the software versions used in teaching , It's all here , Convenient for everyone to download : /k/helloworld/helloworld-version/1718.html

Upload screenshot