Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

867 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

22 Experts available now in Live!

Get 1:1 Help Now