CSCI 1112 Lecture Notes - Lecture 1: Dynamic Array, Abstract Type

36 views3 pages
20 Jan 2017
School
Course

Document Summary

Copying arrays int[] x = new int[10]; int[] y = new int[10]; For (int i = 0; i < 10; i++){ y[i] = x[i]; y = arrays. copyof(x, 10); Basically is better than array, because array has a fixed size. Arraylist, however, does not a default size, it continues to grow as you add elements to it. Arraylist is a generic class, you can specify the type of object in the array list; the type must be a java class (not a primitive type like int) In java, like integer, are objects that are already stored inside java. Arraylist x = new arraylist(); x. add(3); int newnumber = 100; x. add(newnumber); Removing elements from an arraylist x. remove(0) int index = 1; x. remove (index); x. removerange(5,10); x. remove((integer)3); // remove the first occurrence of 3. Random arraylist methods x. get(index); //returns the value or object stored at the index indicated x. contains(element); //checks if the element in the parenthesis is in the arraylist.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions