I\'m looking at a path finding tutorial and I noticed a return
statement inside a void
method (class PathTest
, line 126):
See this example, you want to add to the list conditionally. Without the word "return", all ifs will be executed and add to the ArrayList!
Arraylist list = new ArrayList<>();
public void addingToTheList() {
if(isSunday()) {
list.add("Pray today")
return;
}
if(isMonday()) {
list.add("Work today"
return;
}
if(isTuesday()) {
list.add("Tr today")
return;
}
}