ArrayLists and Primitive Types .edu
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 searches
- minecraft edu edition
- minecraft edu download free
- minecraft edu edition recipes
- minecraft edu mod download
- minecraft edu launcher download
- minecraft edu free download
- alsde edu contacts
- edu perfect
- edu minecraft launcher
- department of elementary and secondary edu mo
- owl purdue edu research and citation mla
- primitive and country home decor