iterator questions ...

Posted on 2006-04-21
Last Modified: 2010-04-17
Hello experts,

   Can anyone please tell me what I did wrong from line 00 - lin02    

    List lineArray = new ArrayList();
    Iterator it = lineArray.iterator();

     if ("DataDictionary")) {
                if (pmml.getDataDictionary() == null) {
                    DataDictionary dataDictionary = pmml.addNewDataDictionary();
                    String str1 = it.toString();   // line 00
                    myPath.add(str1);    // line01
                    System.out.println("path " + str1);  // line02
Question by:meow00
    LVL 3

    Accepted Solution

    Hi meow00!

    Shouldn't the code be this way:

    ----------------------- CODE ---------------------------
    List lineArray = new ArrayList();
    Iterator it = lineArray.iterator();

    String currStr = "";

    while (!currStr.equals("DataDictionary") && it.hasNext())     //You iterate the array to find the correct object
         currStr =;

    if (currStr.equals("DataDictionary"))     //If there was a found item
         if (pmml.getDataDictionary() == null)
              DataDictionary dataDictionary = pmml.addNewDataDictionary();

              myPath.add(currStr);    //When you called "next()" again, you lost the previous object
              System.out.println("path " + currStr);


    LVL 2

    Assisted Solution

    in ur code u just created arraylist and gets its iterator. there are no objects in the list
    but still u are calling this may cause an exception

    so it is better to check if next element is available or not

    ur code should be as

    List lineArray = new ArrayList();
    Iterator it = lineArray.iterator();

    if(it.hasNext()) {
         if( ((String)"DataDictionary") ) {
            // ..................

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Windows 10 SmartScreen vs ClickOnce app 5 89
    canBalance challenge 34 56
    userCompare  challenge 3 54
    groovy example issue 10 33
    Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
    This is an explanation of a simple data model to help parse a JSON feed
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now