Moonear Moonear - 4 months ago 25
Java Question

Java list method declaration?

I am having difficulty understanding this code. I'm unsure if the line that contains a comment is declaring a method or not. I tried googling for list methods but unfortunately didn't find anything. Thank you :)

List<String> getBrands(String color) {//I don't understand this line of code
List<String> brands = new ArrayList<String>();
if(color.equals("amber")) {
brands.add("Jack Amber");
brands.add("Red Moose");
} else {
brands.add("Jail Pale Ale");
brands.add("Gout Stout");
}
return brands;
}

}

Answer

It's declaring the method of return type List<String>, string being the generic type of the list.

Comments