Results 1 to 5 of 5
  1. #1
    cassysumandak is offline Member
    Join Date
    Mar 2009
    Posts
    38
    Rep Power
    0

    Default How to print the content of List

    How to print the content of Linked List?

    Java Code:
    ....
    java.util.List<Polygon> triangles = new LinkedList<Polygon>();
    .....
    
    int[] xs = { startDrag.x, endDrag.x, midPoint.x };
    int[] ys = { startDrag.y, startDrag.y, midPoint.y };      
    triangles.add( new Polygon(xs, ys,3)); 	
    
    ......
    System.out.println (Arrays.toString(triangles)) //this doesnt work

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Your attempt won't work since List is not an array, but Collections toString should automatically iterate through each item in the list, so
    Java Code:
    System.out.println(triangles);
    should work if Polygon has a decent toString method (I'm not sure if it does or not).

  3. #3
    cassysumandak is offline Member
    Join Date
    Mar 2009
    Posts
    38
    Rep Power
    0

    Default

    I got this output..instead of the vertices of polygon. How can I get the vertices instead of this output?

    java.awt.Polygon@53c015
    java.awt.Polygon@253498
    java.awt.Polygon@17172ea
    java.awt.Polygon@b169f8

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    You did not read Fuburable's post above.

  5. #5
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    804
    Rep Power
    6

    Default

    It printed polygon object stored in List.Using that object u try to get the vertices of the polygon class.
    Ramya:cool:

Similar Threads

  1. Replies: 2
    Last Post: 05-30-2009, 10:42 AM
  2. Java code to connect printer to print content
    By wendyz in forum Advanced Java
    Replies: 3
    Last Post: 04-30-2009, 06:51 PM
  3. Linked List integer list
    By igniteflow in forum Advanced Java
    Replies: 1
    Last Post: 12-10-2008, 08:53 PM
  4. How to access ArrayList in List of List?
    By alvations in forum New To Java
    Replies: 5
    Last Post: 10-08-2008, 12:23 PM
  5. Print the text file and print preview them
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-22-2008, 11:04 PM

Posting Permissions

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