Java chapter

public String getTopics(){
return topics;

}

public String getTopTopic(){

return topics[0];

}

why did we use “” in the first one but not in second return statements??

You didn’t mention the exercise name or provide a link to the exercise.
But based on the above snippet, topics is an array of strings. The getTopics method returns this array of strings. Therefore, the return type of the first method is String[] i.e. an array of strings.

The second method getTopTopic only returns the first element of the topics array. Since topics is an array of strings, therefore the first element will be a string. Since the second method is returning just one string (and not the whole array), so the return type of the method is String.

1 Like

first of all thanks for the quick response and sorry for not metioning the link,

Now completely understand the project

thanks again!