0

Is it possible to write an enum in java as below?

public enum SomeEnum{

ADDRESS("someData", arraylist);
}

Basically is it possible to keep list inside Enum ?

1
  • You could wait till january 3rd to stop following your resolution to search before asking. Come on! Commented Jan 2, 2014 at 10:12

2 Answers 2

1

Define like below, Since Enums are constant, you need to pass your array list in compilation time.

public enum SomeEnum{
  String name;
  ArrayList data;

SomeEnum(String name, ArrayList data) {
  this.name = name;
  this.data=data;
}

  ADDRESS("someData", new ArrayList()); // pass your arraylist here
}
Sign up to request clarification or add additional context in comments.

Comments

0

Yes, Enum is just like a class. It can have attribute and methods.

3 Comments

Karnaow , could u please tell me how can i write ENUMCONSTANT("someValue", listOfValues);
@user755806: Just go through the mentioned link. Try something and come back if you face any issue.
@ZouZou: Thanks, not worried about downvote. Just hate it when they gift them without a reason.

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.