From 2353a3c02ae513b335f19b466f5c7905a3288e13 Mon Sep 17 00:00:00 2001 From: Daniel Damilare <31683602+cimthog@users.noreply.github.com> Date: Fri, 29 Mar 2019 23:10:05 +0100 Subject: [PATCH] Update index.md (#29031) --- guide/english/java/arraylist/index.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/guide/english/java/arraylist/index.md b/guide/english/java/arraylist/index.md index 68a14333d0..759cf1bbbc 100644 --- a/guide/english/java/arraylist/index.md +++ b/guide/english/java/arraylist/index.md @@ -9,20 +9,18 @@ title: ArrayList ```java import java.util.ArrayList; // is more efficient than importing all of java.util ``` + +Always import the most specific package in order to save memory size and performance time. + +`ArrayList` is a class that is used to create dynamic arrays. It is slower than regular arrays but allows for a lot of manipulation. It should be initialized to have a specific size or it will have the default size of 10 units. - Always import the most specific package in order to save memory size and performance time. - - - `ArrayList` is a class that is used to create dynamic arrays. It is slower than regular arrays but allows for a lot of manipulation. It should be initialized to have a specific size or it will have the default size of 10 units. - - ```java ArrayList names = new ArrayList<>(); ArrayList ages = new ArrayList<>(5); ``` - In the above snippet, the angle breackets `<>` take a generic data type as argument specifying data type of the elements in the ArrayList. The first ArrayList `names` is specified as containing *String* elements. Thus, it will only be allowed to contain String elements. Its size is not specified so it will have a default size of 10. The second ArrayList `ages` has specified that it will only hold integers. But ArrayList cannot hold primitives, it only holds objects. Thus to make it store integers, floats, etc., we can use wrapper classes. `names` will have a specified size of 5. +In the above snippet, the angle brackets `<>` take a generic data type as argument specifying data type of the elements in the ArrayList. The first ArrayList `names` is specified as containing *String* elements. Thus, it will only be allowed to contain String elements. Its size is not specified so it will have a default size of 10. The second ArrayList `ages` has specified that it will only hold integers. But ArrayList cannot hold primitives, it only holds objects. Thus to make it store integers, floats, etc., we can use wrapper classes. `names` will have a specified size of 5. Since ArrayList implements *List*, an ArrayList can be created using the following syntax: ```java