1
public enum CostData {
    IMPRESSIONS("Impressions", "Impressions"),
    CLICKS("Clicks", "Clicks"),
    COST("Expenditure", "Cost"),
    CONVERSION("Conversion", "Conversions");

    private String value1;
    private String value2;

    private CostData(String value1, String value2) {
        this.value1 = value1;
        this.value2 = value2;

    }

    public String getValue1() {
        return value1;
    }

    public String getValue2() {
        return value2;
    }
}

I need to create an array with Impressions, Clicks, Expenditure and Conversion, the first element in each enum element, another array with the second set in each enum element. Any suggestions?

2 Answers 2

1

If I understand correctly what you want to do is:

List<String> firstArray = new ArrayList<String>();
List<String> secondArray = new ArrayList<String>();
for(CostData c : CostData.values()) {
    firstArray.add(c.getValue1());
    secondArray.add(c.getValue2());
}
Sign up to request clarification or add additional context in comments.

Comments

0

If I get it right you should be doing this.

    int length = CostData.values().length;
    String[] firstArray = new String[length];
    String[] secondArray = new String[length];
    int idx = 0;
    for(CostData cd: CostData.values()){
        firstArray[idx] = cd.getValue1();
        secondArray[idx++] = cd.getValue2();
    }

1 Comment

Thanks, Redcrow and Pura. I'll try it out later.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.