Skip to content

De-rusted my Java skills.#17

Open
HumaGitGud wants to merge 3 commits intoauberonedu:mainfrom
HumaGitGud:main
Open

De-rusted my Java skills.#17
HumaGitGud wants to merge 3 commits intoauberonedu:mainfrom
HumaGitGud:main

Conversation

@HumaGitGud
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown
Owner

@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! See comments below

Comment thread src/ListPractice.java
public class ListPractice {
public static void main(String[] args) {
// Create an empty ArrayList of Strings and assign it to a variable of type List
ArrayList<String> myList = new ArrayList<>();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Remember to use interface types (List)

Comment thread src/MapPractice.java
public static void main(String[] args) {
// Create a HashMap with String keys and Integer values and
// assign it to a variable of type Map
HashMap<String, Integer> map = new HashMap<>();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Remember to use interface types (Map)

Comment thread src/Person.java
Comment on lines +38 to +40
public int birthYear(int age, int currentYear) {
return currentYear - age;
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This doesn't quite match the Javadoc description. It should only take a single argument, currentYear. The age is already stored as an instance variable, so you don't need to get it again as an argument

Comment thread src/SetPractice.java
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> set = new HashSet<>();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Remember to use interface types (Set)

Comment thread src/StringPractice.java

// Create an ArrayList of Strings and assign it to a variable

ArrayList<String> list = new ArrayList<>(Arrays.asList("Strawberry", "Banana", "Grape"));
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Remember to use interface types (List)

Comment thread src/StringPractice.java
// Check whether two strings are equal
String a = "Lol";
String b = "Lolo";
System.out.println(a == b);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Strings in Java should typically be compared using .equals, not == (see the comment that was at the bottom of this file)

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