Fixed typo, improved readability. (#32580)

This commit is contained in:
Randy Janecek
2019-05-11 12:25:33 -04:00
committed by The Coding Aviator
parent 152a73c81a
commit 23cc43c301

View File

@ -19,7 +19,7 @@ Always import the most specific package in order to save memory size and perform
ArrayList<String> names = new ArrayList<>(); ArrayList<String> names = new ArrayList<>();
ArrayList<Integer> ages = new ArrayList<>(5); ArrayList<Integer> ages = new ArrayList<>(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. 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: Since ArrayList implements *List*, an ArrayList can be created using the following syntax: