ArrayLists and Primitive Types
Computer Programming II Instructor: Greg Shaw
COP 3337
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
- primitive society characteristics
- life in a primitive society
- java primitive array to list
- java primitive data types
- char primitive type in java
- primitive percussion instrument crossword
- primitive society meaning
- primitive society definition
- primitive definition music
- primitive culture definition
- what is primitive law
- primitive times