Java ArrayList printing the index twice

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • javamate
    New Member
    • Jun 2006
    • 3

    #1

    Java ArrayList printing the index twice

    I assigned a string by for loop to an arrayList but when printing the result it will print each index twice, I solve this problem by modifying for loop to increase by.

    for (int i = 0, i< x.getLength() ;i++)
    {
    Node child = children.item(i );
    {
    name = child.getNodeNa me()

    }
    myArrayList.add (name)
    }
    for (int s = 0, s< x myArrayList.siz e() ;s = s + 2 )
    System.out.prin tln(myArrayList (y)); // Printing twice
    }
  • D_C
    Contributor
    • Jun 2006
    • 293

    #2
    Is it possible that you are adding each entry twice? You could verify that by printing s as well as MyArrayList y. Only increment s by one when you do this.

    Comment

    Working...