COMP 202 Lecture Notes - Lecture 24: Foreach Loop
jc123 and 40170 others unlocked
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.