dimanche 19 avril 2015

How can I access only Strings from [0 to 9] outside for loop?

I am trying to write a code that allows me to access String msgbody and place it in an email. However, using the following code only the final String shows up outside the for loop. I searched many times for an answer, and am a bit new to Java.



List<String> urls = new ArrayList<String>();
String msgbody = "";
for (int i = 0; i < urls.size(); i++) {
urls.get(i);
// String msgbody0; - Used to attempt msgbody0 = url.get(i); then msgbody += msgbody0; but only prints first url
int sum = i + 1;
for (j = 1; j < 2 ; j++)
{
msgbody = urls.get(i);

urls.add(msgbody);
System.out.print("("+ sum +")" +"");
System.out.println(msgbody);
}
if(i==9){
break;
}
} // Inside the for loop everything prints properly.

System.out.println(msgbody); // How can i replicate it here?(Outside for loop)

Aucun commentaire:

Enregistrer un commentaire