Skip to content

Java Derusting Assignment #10

Open
Azeb-S wants to merge 10 commits intogrc-cohort-22:mainfrom
Azeb-S:main
Open

Java Derusting Assignment #10
Azeb-S wants to merge 10 commits intogrc-cohort-22:mainfrom
Azeb-S:main

Conversation

@Azeb-S
Copy link
Copy Markdown

@Azeb-S Azeb-S commented Oct 1, 2025

No description provided.

Copy link
Copy Markdown

@auberonedu auberonedu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job!

Comment thread src/ListPractice.java
public static void main(String[] args) {
// Create an empty ArrayList of Strings and assign it to a variable of type List

ArrayList<String> daysOfTheWeek = new ArrayList<String>();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

And sets:
Set<String> strings = new HashSet<>();
Note that on the left we use Set instead of HashSet.

In summary:

  • interface type on left to declare type (List, Map, etc.)
  • Concrete type on right to instantiate instance (HashMap, ArrayList etc.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants