Solved

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

Posted on 2001-06-15
5
230 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

760 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

17 Experts available now in Live!

Get 1:1 Help Now