[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2001-06-15
5
Medium Priority
?
254 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
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 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.
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.
Suggested Courses

649 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