Here is the code, that works:
public class WorkshopApplicationMyCollection {
static void listOfPeople(List<String> someList) {
for (int i = 0; i<someList.size(); i++){
if (i == someList.size()-1) {
System.out.print(someList.get(i) + ". \n");
} else {
System.out.print(someList.get(i) + ", ");
}
}
}
public static void main(String[] args) {
List<String> listOfPeople = new ArrayList<>();
listOfAuthorities.add("Musk");
listOfAuthorities.add("Davinchie");
listOfAuthorities.add("Gates");
System.out.print("Number of people " + listOfPeople.size() + ". Those people are ");
listOfPeople(listOfAuthorities);
}
}
What I'm trying to do is to make a result of a method listOfPeople() to be a string by itself so that I could put it into the sentence. when I'm doing like this:
System.out.print("Number of people " + listOfPeople.size() + ". Those people are " + listOfPeople(listOfAuthorities));
the IDE says that the method has to not be void. How to make the method return string on it's own?