Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By eRaaaa

Thread: Printing values from Array on individual lines

  1. #1
    Castle is offline Member
    Join Date
    Nov 2012
    Posts
    9
    Rep Power
    0

    Default 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

    Java 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?

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    786
    Rep Power
    5

    Default 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.
    Castle likes this.

  3. #3
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    757
    Rep Power
    7

    Default Re: Printing values from Array on individual lines

    Quote Originally Posted by Castle View Post
    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.

Similar Threads

  1. Sorting and printing multiple lines of data
    By ManInTheMiddle in forum New To Java
    Replies: 1
    Last Post: 03-27-2012, 09:43 PM
  2. Printing to the screen specific lines from a file
    By stevenhaynes5 in forum New To Java
    Replies: 9
    Last Post: 08-15-2011, 05:28 PM
  3. reading lines from URL and printing backwards
    By luxurymode in forum Advanced Java
    Replies: 1
    Last Post: 03-30-2011, 08:18 AM
  4. Printing two values
    By vibaviattigala in forum New To Java
    Replies: 1
    Last Post: 02-19-2011, 03:32 AM
  5. Printing values from object in Array?
    By thesinter in forum New To Java
    Replies: 3
    Last Post: 01-20-2010, 05:19 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •