ArrayLists and Primitive Types - School of Computing and ...
Computer Programming I Instructor: Greg Shaw
COP 2210
ArrayLists of Primitive Types
I. “Wrapper” Classes
Java has a class – known as a wrapper class – associated with each of the primitive types.
|Primitive Type |Wrapper Class |
|double |Double |
|int |Integer |
|boolean |Boolean |
|char |Character |
To create an ArrayList to store primitive type values, we use the wrapper class.
For example, to create an ArrayList to store int values:
ArrayList list = new ArrayList() ;
II. Storing a Primitive Type Value in an ArrayList
Since Java 1.5 (aka: “Java 5”), we have been able to store primitive type values in ArrayLists simply by passing them as arguments to the add() and set() methods.
For example, here is a loop that stores the ints 1 through 10 in elements 0 through 9 of an ArrayList:
ArrayList list = new ArrayList() ;
for (int i = 1 ; i ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
Related searches
- types of surgeons and what they do
- types of products and services
- types of surgeons and salaries
- types of lawyers and what they do
- types of doctors and salaries
- types of growth and development
- types of doctors and pay
- different types of mortgages and definitions
- different types of surgeons and salaries
- types of lawyers and descriptions
- types of goods and services
- types of monitoring and evaluation