java - How to call multiple variable of string with numbering in loop? -


what trying achieve is, let's i've these variables below:

string num1 = "blah1"; string num2 = "blah2"; string num3 = "blah3"; string num4 = "blah4"; string num5 = "blah5"; 

now want create single string variable iterate values of string's variable inside loop.

for(int i=0; i<=5; i++){    system.out.println(num+""+i); //i know, give me errors. want make call string variables. } 

here want print values of string's variable using loop, how achieve this?

help appreciated!

this use case array:

string nums[] = new string[] {     "blah1",     "blah2",     "blah3",     "blah4",     "blah5" } 

and can iterate through values (note don't need duplicate number of elements (5) ):

for(int i=0; i<nums.length; i++) {    system.out.println(nums[i]); } 

more arrays on stack overflow documentation.


alternatively, may use list instead of array.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -