I'm trying to create a simple method which I have below:

```
public void analyzeWithAnalytics(String data) {

    for (int i = 0; i < VALUE; i++) {
        if (data.equals("action1")) {
            // call a method on a value
        }
        if (data.equals("action2")) {
            // call a different method on a value
        }
    }

```

This is only a small snippet (I took a lot out of my code), but essentially I want to be able to call a specific method without testing multiple lines in my for loop for which method to call.

Is there a way for me to decide what value to call by declaring a variable at the very beginning, instead of doing so many 'if statement' tests?

OK, I have an ArrayList inside my class:

```
private List<Value> values;

```

The value object has 2 fields time and speed. 

Depending on the string I pass (time or speed), I want to be able to call the specific method for that field without doing multiple string comparisons on what method I passed.

For example, I want to be able to call getSpeed() or getTime() without doing a string comparison each time I want to call it. 

I just want to test it once.