Solved

For loop

Posted on 2004-10-19
8
195 Views
Last Modified: 2010-03-31
What does the following for loop mean?

for (NamingEnumeration enu=attr.getAll();enu.hasMore();System.out.println("value: " + enu.next()));

Does it mean,

for (NamingEnumeration enu=attr.getAll();enu.hasMore(); )
    System.out.println("value: " + enu.next());

??
0
Comment
Question by:jtcy
  • 7
8 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 12346300
yes
0
 
LVL 37

Accepted Solution

by:
zzynx earned 20 total points
ID: 12346323
Like

   for (int i=0; i<5; System.out.println(i++));

means

   for (int i=0; i<5; i++)
        System.out.println(i);
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12346332
Or
        for (int i=0; i<5;)
          System.out.println(i++);
0
 

Author Comment

by:jtcy
ID: 12346361
Why is this fine:

System.out.println("value: " + enu.next()));

but when I do:

String smth = enu.next();, it says incompatible error?, Should I do:

String smth = (String) enu.next();?
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 37

Expert Comment

by:zzynx
ID: 12346389
yes
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12346390
next() returns an Object, you have to cast
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12346405
Writing

      System.out.println( "value: " + enu.next() );   // with two closing )'s at the end

is like writing

      System.out.println( "value: " + enu.next().toString() );
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12346500
Thanks
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

758 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

21 Experts available now in Live!

Get 1:1 Help Now