Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

syntax for repeating a parameter in code?

 
Michele Smith
Ranch Hand
Posts: 421
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 344
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String[] videoNames; ???
Not sure what you're asking.
 
Michele Smith
Ranch Hand
Posts: 421
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes particularly in this code:



AND



Thanks, Michele
 
Koen Aerts
Ranch Hand
Posts: 344
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 421
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
like this:

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

 
Rob Spoor
Sheriff
Pie
Posts: 20606
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Michele Smith
Ranch Hand
Posts: 421
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you help me get started?

Thanks,
Michele
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic