This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Why getParameterNames() returns Enumeration, not String[] like getParameterValues()? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Why getParameterNames() returns Enumeration, not String[] like getParameterValues()?" Watch "Why getParameterNames() returns Enumeration, not String[] like getParameterValues()?" New topic
Author

Why getParameterNames() returns Enumeration, not String[] like getParameterValues()?

Faisal Ahmad
Ranch Hand

Joined: Aug 31, 2006
Posts: 347

Why GenericServletRequest.getParameterNames() returns java.util.Enumeration<java.lang.String>? Returning java.lang.String[] is much better, right? Like, java.lang.String[] getParameterValues(java.lang.String name).
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

That's just the way it was defined way back when the servlet interfaces were first defined. It can't be changed without breaking backward compatibility, even though modern interfaces rarely return Enumerations anymore.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

Faisal Ahmad wrote:Returning java.lang.String[] is much better, right? Like, java.lang.String[] getParameterValues(java.lang.String name).

Personally, I wouldn't use either. Were I defining the interface, I'd use a List.
 
wood burning stoves
 
subject: Why getParameterNames() returns Enumeration, not String[] like getParameterValues()?
 
Similar Threads
HttpServletRequest - catch duplicate request header names
servlet is not working properly
deviation in the return type of getParameterValues() method
Getting value of radio button
Unable to get value of URL parameter