return statement in List<String> method?

red bean :

I am currently trying to catch up in my AP computer science class and the FRQs (coding without the compiler) is extremely difficult to me, so I've taken to the step of using the compiler to make sure what I am teaching myself is correct.

From the question itself:

"A database of all the businesses in a city along with their street addresses can be stored using the following classes. The following complete Address class is used to represent businesses and their addresses. An Address object cannot be modified after it has been constructed.

Write the AddressList method onStreet. This method returns a list of String objects containing the name for each business in addresses for which street is equal to st."

the method header is:

public List<String> onStreet(String st){}

I've tried using a for loop to print out each index of the List, as well as making a new String[] and using the toArray method but I still can't figure out how to print it using the return statement.

Also, I've barely used this site and I've come out of desperation during the Covid madness since I can't get a hold of my teacher, excuse any malpractice on the site.

androidForEveryone :

I assume that you have a list of businesses

First, define a List rightBus. Now, you have to use a while loop, moving from every node to the next one(unless it’s null - if it’s null, you don’t continue). In the while loop, you check for every business in your original list if it’s street name is equal to st -> if it does -> you add it to the rightBus.

Then, at the last row of the method, you write:

return rightBus.

Good luck my friend, don’t hesitate to quote me if it’s needed.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=366969&siteId=1