Java Java Data Structures Exploring the Java Collection Framework Sets

Eric Tang
PRO
Eric Tang
Pro Student 1,300 Points

for(Treet treet: treets)

It's really hard and confusing to wrap my head around this line. I've seen instances of these sort of usage. I don't understand why the word "Treet" is infront of the variable Treet. If it was Strings I would get it but why Treet. Can someone run through what this line actually does. Is the line grabbing resource from the Treet class?

1 Answer

Vladut Astalos
Vladut Astalos
11,246 Points

Just like when you use String in front of a variable to declare an object of type String you use Treet in front of a variable to declare an object of type Treet. The only difference is that Treet is a custom class you created on your own while String is a built-in class.