I was looking at this piece of code and can not understand what the .add statement is doing (fromCity) and (toCity) is just Strings?
getDestinations(fromCity).add(toCity);
Method:
public ArrayList<String> getDestinations(String fromCity)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is called
chaining of method calls. You are invoking the next method on the return value of the previous method.So, the
getDestinations()method returns you aArrayList, now instead of storing your returning value, you are invoking theaddmethod of theArrayListon the method call.This is equivalent to: –
Similarly you can chain method calls upto any lavel: –