I'm working on some software at the moment and I'm not sure which route to take with this. I have to use some tabular data which may get change rarely, so I can use the collection for it but it will be hardcode which I don't want.what will be the best way so that I can get the data in less time.

  • Sharing your research helps everyone. Tell us what you've tried and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer. Also see How to Ask – gnat Jan 4 at 13:24
  • I have tried it by using storing the data in string array list with each string as row separated by the delimiter, as data may change rarely I need to deploy code everytime which I don't want. Note: columns values will not change – MAx Jan 4 at 13:30
  • A file in the file system you read at start up? A resource in your classpath you read at start up? – Thorbjørn Ravn Andersen Jan 4 at 13:30
  • Don't understand what using a collection has to do with whether or not it's hard coded. – candied_orange Jan 4 at 22:36

You should be careful to ensure that this data isn't likely to change. If it is likely to change often, then you should consider other approaches such as serializing configuration to a file or to a database.

However assuming this isn't the case, generally you'd use an enum for this information:

public enum UserType {
    USER (false, false, true),
    ADMINISTRATOR (false, true, true),
    SUPERADMINISTRATOR (true, true, true);

    public final boolean canModifyUsers, canModifyData, canReadData;

    private UserType(boolean canModifyUsers, boolean canModifyData, boolean canReadData) {
        this.canModifyUsers = canModifyUsers;
        this.canModifyData = canModifyData;
        this.canReadData = canReadData;

UserType for instance, can tell you whether or not a given user with a certain UserType instance can read/write data without having to write out an explicit if/else chain. If you wanted to serialize this information, you'd simply call its toString() method to get the name equivalent or UserType.valueOf(String) to deserialize.

Though I used the example of permissions, the information is arbitrary. It is useful to link information one-to-one with a general concept.

In this case, if you wanted to add an additional user type in the future, it would not be too difficult to expand, though again, it is my opinion that it would be a mistake to use enum here if you thought changes are likely.

If something isn't clear, just ask in the comments and I'll correct my answer.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.