?
Solved

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

Posted on 2001-06-15
5
Medium Priority
?
248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 400 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

741 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