Retrieving the value of a concatenated variable within a Java FOR loop

Posted by Rajat on Stack Overflow See other posts from Stack Overflow or by Rajat
Published on 2010-05-24T19:40:23Z Indexed on 2010/05/24 19:51 UTC
Read the original article Hit count: 118

Filed under:
|

I have been using this "logic" in C++ and VB with success, but am tied up in Java... Simply put,

public void DataProviderExample(String user, String pwd, String no_of_links,
        String link1, String link2, String link3) {

for (int i=1;i<=no_of_links;i++) {
         String link = "link"+i;
         System.out.println(link);
}   

Now, if the variables link1, link2 and link3 have a value of "X", "Y" and "Z" respectively, upon running this program, I get the following output -

link1
link2
link3

What I want is -

X
Y
Z

Any ideas?

© Stack Overflow or respective owner

Related posts about java

Related posts about loops