Can i use a String as variable in java
<p>I have two arrays, with Filenames and JTextFields. If files exists, i would like to fill the path in the JTextField. Is there a way to this with a for loop ? I also tried it with a Hashmap, but this isn't working.</p>

<pre><code>String[] Dateiliste = {
                    "A.txt",
                    "B.txt",
                    "C.txt",
                    "D.txt",
                    "E.txt",
                    "F.txt"
            };

String[]textliste ={
                    "text1",
                    "text2",
                    "text3",
                    "text4",
                    "text5",
                    "text6",
            };

Map&lt;Integer, String&gt; Dateilistestreda = new HashMap&lt;Integer,String&gt;();
Dateilistestreda.put(0,"text1");
Dateilistestreda.put(1,"text2");
Dateilistestreda.put(2,"text3");
Dateilistestreda.put(3,"text4");
Dateilistestreda.put(4,"text5");
Dateilistestreda.put(5,"text6");

    for (int i = 0; i &lt; Dateiliste.length; i++){
        File f = new File (path + "\\" +Dateiliste[i]);
        System.out.println(f);
        if (f.exists() &amp;&amp; !f.isDirectory()){
            Dateilistestreda.get(i).setText(f.toString());
        }
    }
</code></pre>