How to use an array value as field in Java? a1.section[2] = 1;
<p>New to Java, and can't figure out what I hope to be a simple thing.</p>

<p>I keep "sections" in an array:</p>

<pre><code>//Section.java
public static final String[] TOP = {
    "Top News",
    "http://www.mysite.com/RSS/myfeed.csp",
    "top"
};
</code></pre>

<p>I'd like to do something like this:</p>

<pre><code>Article a1 = new Article();
a1.["s_" + section[2]] = 1;  //should resolve to a1.s_top = 1;
</code></pre>

<p>But it won't let me, as it doesn't know what "section" is.  (I'm sure seasoned Java people will cringe at this attempt... but my searches have come up empty on how to do this)</p>

<p><strong>Clarification:</strong></p>

<p>My article mysqlite table has fields for the "section" of the article:</p>

<pre><code>s_top
s_sports
...etc
</code></pre>

<p>When doing my import from an XML file, I'd like to set that field to a <code>1</code> if it's in that category.  I could have switch statement:</p>

<pre><code>//whatever the Java version of this is
switch(section[2]) {
    case "top": a1.s_top = 1; break;
    case "sports": a1.s_sports = 1; break;
    //...
}
</code></pre>

<p>But I thought it'd be a lot easier to just write it as a single line:</p>

<pre><code>a1["s_"+section[2]] = 1;
</code></pre>
