Solved

creating a class that has this in it : (for (final Iterator iter = set.iterator();...)

Posted on 2001-06-15
5
238 Views
Last Modified: 2013-12-14
Hello

I have to create a class that has this :

"for(final Iterator iter=set.iterator();...)"

I really do not know where to begin could someone help
me :)

Thanks in advance.

0
Comment
Question by:willcont
5 Comments
 
LVL 7

Expert Comment

by:Sasha_Mapa
ID: 6195744
Umm, here's an example:

for (Iterator iterator = set.iterator();iterator.hasNext();){
  Object item = iterator.next();
  System.out.println(element);
}

I'm not sure why you need the iterator to be final. Also, I would consider this a cleaner (more readable) way to do this:

Iterator iterator = set.iterator();
while (iterator.hasNext()){
  Object item = iterator.next();
  System.out.println(item);
}


Sasha Maryanovsky.
0
 

Author Comment

by:willcont
ID: 6196058
Okay so at the beginning before the "for"
class IteratorExample {

  public static IterEx{
  <and here I would put what you suggested>

Sorry for my ignorance I am a beginner.

Also for the first question you answered I tried
to compile your Vector class and I got the following
compilation error :
Vector.java:10: illegal start of expression
        if (i<0)||(i>=size))
                ^
1 error

I have not been able to compile and check when it throws the IndexOutOfBoundsException

:) Please help :)

0
 
LVL 7

Accepted Solution

by:
Sasha_Mapa earned 100 total points
ID: 6196090
I suggest you read the java tutorial : http://java.sun.com/tutorial

As for my previous answer:
A. It wasn't meant as a complete class - it's not even a runnable application, just an example.
B. You forgot a parentheses, it's "if ((i<0)||(i>=size))", not "if (i<0)||(i>=size))"

Sasha Maryanovsky.
0
 
LVL 92

Expert Comment

by:objects
ID: 6199125
> I have to create a class that has this

Out of curiosity, why ???
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 8950690


No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:


--  points to Sasha_Mapa


Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
sudhakar_koundinya
EE Cleanup Volunteer
---------------------
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

730 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