Moonear Moonear - 1 year ago 142
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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download