System.out.print accepts a String as a parameter, in fact, anything that you send it will be converted to a String in order for it to be displayed.
Using the following code, you could then put the result of the postalCodeIndex method call into a variable called myString.
String myString = postalCodeIndex.findClosestBruteForce(latitude, longitude).toString();
It might be worth your while remembering that the process in the System.out.print() code sample works as follows:
- postalCodeIndex is called FIRST, creating a temporary String in-place because the .toString() method is called on your behalf.
- The System.out.print method is only called AFTER the postalCodeIndex method has returned, because System.out.print requires this returned String to enable it to print something to the console.