Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enumeration to string

Status
Not open for further replies.

sandeepmur

Programmer
Joined
Dec 14, 2003
Messages
295
Location
PT
Hi,

I have an enumeration in a code I am trying to debug. .something like:

for (Enumeration vals = attr.getAll();vals.hasMoreElements();)
{
out.println (vals.nextElement()+ "<br>");
//String nval = (String)vals.nextElement();
}
The above works fine and prints all the elements but If I try to cast the elements into Strings as seen in the commented line, the code stops execution after the first print statement.

Whats wrong here ??

tia
 
The element in the enum is not a String ...

try this :

Code:
for (Enumeration vals = attr.getAll();vals.hasMoreElements();) {
   Object o = vals.nextElement();
   if (o instanceof java.lang.String) {
   		String nval = (String)vals.nextElement();
   } else {
	   System.err.println("Uh oh, its not a String, its a : " +o.getClass().getName());
   }
}

--------------------------------------------------
Free Database Connection Pooling Software
 
nevermind.. solved the problem, there was a bug elsewhere which caused this problem..

thnx a bunch though!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top