Conversation
auberonedu
left a comment
There was a problem hiding this comment.
Nice job! You don't need to say "commit" at the end of your commit messages. You could write something like "Finished ArrayPractice exercises"
|
|
||
| public static void main(String[] args) { | ||
| // Create an empty ArrayList of Strings and assign it to a variable of type List | ||
| List<String> ArrayList = new ArrayList<>(); |
There was a problem hiding this comment.
I recommend not naming variables the exact same name as classes. Our local variables should be camelCase (note that it starts with a lowercase letter). Naming a variable ArrayList (with a capital A) when there is already an ArrayList class is confusing and can lead to problems.
| public class SetPractice { | ||
| public static void main(String[] args) { | ||
| // Create a HashSet of Strings and assign it to a variable of type Set | ||
| HashSet<String> Strings = new HashSet<>(); |
There was a problem hiding this comment.
Here and elsewhere, use interface types (List, Map, etc.) where appropriate.
For example:
List<String> strings = new ArrayList<>();
Note that the type on the left is List, not ArrayList. When we do this, we're more flexible to be able to change our code to use a different type of list later.
Similarly for maps:
Map<String, String> myMap = new HashMap<>();
Note that on the left we use Map instead of HashMap.
In summary:
- interface type on left to declare type (List, Map, etc.)
- Concrete type on right to instantiate instance (HashMap, ArrayList etc.)
No description provided.