wood burning stoves*
The moose likes Servlets and the fly likes syntax for repeating a parameter in code? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "syntax for repeating a parameter in code?" Watch "syntax for repeating a parameter in code?" New topic
Author

syntax for repeating a parameter in code?

Michele Smith
Ranch Hand

Joined: Oct 27, 2010
Posts: 412
I wondered if I have several videos is there a better way to state this?
instead of videoName1, et al etc.? Please see code below. Thanks - Michele
Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

String[] videoNames; ???
Not sure what you're asking.
Michele Smith
Ranch Hand

Joined: Oct 27, 2010
Posts: 412
yes particularly in this code:



AND



Thanks, Michele
Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

Seems like a repetition of code for each videoName* variable. Can be shortened if you use an array: "String[] videoNames". Then interate throught the array: "for (String videoName : videoNames) { ... }" after it has been populated. Unless your code below is not complete or doesn't show the whole picture, videoName2 and videoName3 always seem to contain an empty String.
Michele Smith
Ranch Hand

Joined: Oct 27, 2010
Posts: 412
like this:

"{\"name\":\"" + int [] videos = { OS_FILE, AV_FILE, VT_File }; + "\", " +

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

You do know how to use a loop, do you? You then create one, and put all the code you now have three times inside that loop once.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Michele Smith
Ranch Hand

Joined: Oct 27, 2010
Posts: 412
Can you help me get started?

Thanks,
Michele
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: syntax for repeating a parameter in code?
 
Similar Threads
Getting java.io.FileNotFoundException:(The system cannot find the file specified) error
New Servlet, Has a One Errors on it
Need to hook two servlets together, how do I do that?
Help Package Servlet Error
Help Modifying Servlet Please