COMP 202 Lecture Notes - Lecture 24: Foreach Loop

36 views4 pages
jc123 and 40170 others unlocked
COMP 202 Full Course Notes
100
COMP 202 Full Course Notes
Verified Note
100 documents

Document Summary

Not a set: {2, 3, 4,2} Comp 202 lecture 24 hash set, hash map, and recursion. The foreach loop aka enhanced for loop) Sets: a collection of distinct elements. This order is not defined and the elements are unique. To use it: import java. util. hashset; Hashset aset = new hashset (); (there is no concept of index) Hashset uniquewords = new hashset (); uniquewords. add( apples ); uniquewords. add( oranges ); uniquewords. add( apples ); There is no guarantee of the order in which you will see the elements. A hashset where each element of the set is associated with another value. The types of the key and value are determined when the hashmap is created. To use it: import java. util. hashmap; Hashmap grades = new hashmap (); String is the type of the key. Integer is the type of the value. With arraylists, we access elements using their positions. With hashmaps, we use the keys to access values.

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