Printing values from Array on individual lines
I want to print the values from an array, at the moment it prints out like: [url1, url2, url3, url4]
and I want to print it like this:
url1
url2
url3
url4
Code:
public void print(ArrayList<String> urls) {
//for (int i = 0; i<urls.size(); i++){
System.out.println(urls);
//}
}
How do I separate the 'urls' so they don't print together on one line but on separate lines?
Re: Printing values from Array on individual lines
The loop is correct, remove the comments and use urls.get(i) instead of urls or use the for-each-loop.
Re: Printing values from Array on individual lines
Quote:
Originally Posted by
Castle
I want to print the values from an array, at the moment it prints out like: [url1, url2, url3, url4]
Just for adding some information. You get that kind of output because it was a result of calling the toString() method of the ArrayList (it defined in the AbstractCollection class). The toString() method will be called for instance when you try to print out a variable.