Suppose that there is a method called Person.
class Person {
int id;
String name;
String number;
constructor with that values, and getter/setter methods
}
and a method with a return type of String[]
class Test{
List<Person> list = new ArrayList<>;
String[] getValues(int personID) {
for(Person person : list) {
if(person.getId() == personID) {
}
}
}
}
As you can see that if person.getId() is equal to the parameter, "personID", how do we return the values of that matching person in the form of: [name, number] when the return type of that method is String[]?
For example:
main_method() {
(suppose that there are some Persons added to that list through Test test.addList() method)
System.out.println(test.getValues(2));
}
console :
[Tom, 1234]
Thanks in advance!