Best Way to Store List as Constant [on hold]











up vote
-2
down vote

favorite












Let's say I want to parse some JSON and I store the path in a Java constants class the path that I want to follow.



For example:



public static final List<String> path = Arrays.asList("a", "b", "c"); 


so that I can do this (pseudocodeish):



public boolean checkSomething() {
JsonThing json = ...
for (String path : Constants.path) {
json.get(path);
}

return json.getAsString().equals("value");
}


Would it be better to store this constant as a String like:



public static final String path = "a:b:c";


and then do:



public boolean checkSomething() {
JsonThing json = ...
for (String path : Constants.path.split(":") {
json.get(path);
}
return json.getAsString().equals("value");
}


Since the path is already stored in memory, would it be more efficient to just keep a : separated list since that String will take up less space than the array. In this instance, there's a little more work to be done (iterating over String to turn it into list), but then the list is garbage collected when the method is over.










share|improve this question







New contributor




flyinghigh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by πάντα ῥεῖ, t3chb0t, IEatBagels, rolfl 9 hours ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – IEatBagels, rolfl

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 2




    Welcome on Code Review. The code you presented in its current form is not meaningfully reviewable. We only review real, working code. If you edit your question to contain your actual code we can review it for improvements. See What topics can I ask about? for reference.
    – Calak
    9 hours ago










  • Wait really? Is there a better forum for this then? The algorithm is what needs to be reviewed, not working code. If anything, working code would distract from the idea that I'm trying to emphasize. Same reason academic papers don't use compilable code.
    – flyinghigh
    9 hours ago






  • 1




    @flyinghigh Code Review is all about reviewing working code, not an algorithm or hypothetical code, just real, ready-to-use code. Of course you can scope the "working code" to a single function or module or whatever, but here we need the real thing, not just the idea. For the algorithm itself you may take a look at Stack Overflow or maybe Software Engineering Stack Exchange.
    – Alejandro
    8 hours ago















up vote
-2
down vote

favorite












Let's say I want to parse some JSON and I store the path in a Java constants class the path that I want to follow.



For example:



public static final List<String> path = Arrays.asList("a", "b", "c"); 


so that I can do this (pseudocodeish):



public boolean checkSomething() {
JsonThing json = ...
for (String path : Constants.path) {
json.get(path);
}

return json.getAsString().equals("value");
}


Would it be better to store this constant as a String like:



public static final String path = "a:b:c";


and then do:



public boolean checkSomething() {
JsonThing json = ...
for (String path : Constants.path.split(":") {
json.get(path);
}
return json.getAsString().equals("value");
}


Since the path is already stored in memory, would it be more efficient to just keep a : separated list since that String will take up less space than the array. In this instance, there's a little more work to be done (iterating over String to turn it into list), but then the list is garbage collected when the method is over.










share|improve this question







New contributor




flyinghigh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by πάντα ῥεῖ, t3chb0t, IEatBagels, rolfl 9 hours ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – IEatBagels, rolfl

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 2




    Welcome on Code Review. The code you presented in its current form is not meaningfully reviewable. We only review real, working code. If you edit your question to contain your actual code we can review it for improvements. See What topics can I ask about? for reference.
    – Calak
    9 hours ago










  • Wait really? Is there a better forum for this then? The algorithm is what needs to be reviewed, not working code. If anything, working code would distract from the idea that I'm trying to emphasize. Same reason academic papers don't use compilable code.
    – flyinghigh
    9 hours ago






  • 1




    @flyinghigh Code Review is all about reviewing working code, not an algorithm or hypothetical code, just real, ready-to-use code. Of course you can scope the "working code" to a single function or module or whatever, but here we need the real thing, not just the idea. For the algorithm itself you may take a look at Stack Overflow or maybe Software Engineering Stack Exchange.
    – Alejandro
    8 hours ago













up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











Let's say I want to parse some JSON and I store the path in a Java constants class the path that I want to follow.



For example:



public static final List<String> path = Arrays.asList("a", "b", "c"); 


so that I can do this (pseudocodeish):



public boolean checkSomething() {
JsonThing json = ...
for (String path : Constants.path) {
json.get(path);
}

return json.getAsString().equals("value");
}


Would it be better to store this constant as a String like:



public static final String path = "a:b:c";


and then do:



public boolean checkSomething() {
JsonThing json = ...
for (String path : Constants.path.split(":") {
json.get(path);
}
return json.getAsString().equals("value");
}


Since the path is already stored in memory, would it be more efficient to just keep a : separated list since that String will take up less space than the array. In this instance, there's a little more work to be done (iterating over String to turn it into list), but then the list is garbage collected when the method is over.










share|improve this question







New contributor




flyinghigh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











Let's say I want to parse some JSON and I store the path in a Java constants class the path that I want to follow.



For example:



public static final List<String> path = Arrays.asList("a", "b", "c"); 


so that I can do this (pseudocodeish):



public boolean checkSomething() {
JsonThing json = ...
for (String path : Constants.path) {
json.get(path);
}

return json.getAsString().equals("value");
}


Would it be better to store this constant as a String like:



public static final String path = "a:b:c";


and then do:



public boolean checkSomething() {
JsonThing json = ...
for (String path : Constants.path.split(":") {
json.get(path);
}
return json.getAsString().equals("value");
}


Since the path is already stored in memory, would it be more efficient to just keep a : separated list since that String will take up less space than the array. In this instance, there's a little more work to be done (iterating over String to turn it into list), but then the list is garbage collected when the method is over.







performance






share|improve this question







New contributor




flyinghigh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




flyinghigh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




flyinghigh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 10 hours ago









flyinghigh

97




97




New contributor




flyinghigh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





flyinghigh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






flyinghigh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




put on hold as off-topic by πάντα ῥεῖ, t3chb0t, IEatBagels, rolfl 9 hours ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – IEatBagels, rolfl

If this question can be reworded to fit the rules in the help center, please edit the question.




put on hold as off-topic by πάντα ῥεῖ, t3chb0t, IEatBagels, rolfl 9 hours ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – IEatBagels, rolfl

If this question can be reworded to fit the rules in the help center, please edit the question.








  • 2




    Welcome on Code Review. The code you presented in its current form is not meaningfully reviewable. We only review real, working code. If you edit your question to contain your actual code we can review it for improvements. See What topics can I ask about? for reference.
    – Calak
    9 hours ago










  • Wait really? Is there a better forum for this then? The algorithm is what needs to be reviewed, not working code. If anything, working code would distract from the idea that I'm trying to emphasize. Same reason academic papers don't use compilable code.
    – flyinghigh
    9 hours ago






  • 1




    @flyinghigh Code Review is all about reviewing working code, not an algorithm or hypothetical code, just real, ready-to-use code. Of course you can scope the "working code" to a single function or module or whatever, but here we need the real thing, not just the idea. For the algorithm itself you may take a look at Stack Overflow or maybe Software Engineering Stack Exchange.
    – Alejandro
    8 hours ago














  • 2




    Welcome on Code Review. The code you presented in its current form is not meaningfully reviewable. We only review real, working code. If you edit your question to contain your actual code we can review it for improvements. See What topics can I ask about? for reference.
    – Calak
    9 hours ago










  • Wait really? Is there a better forum for this then? The algorithm is what needs to be reviewed, not working code. If anything, working code would distract from the idea that I'm trying to emphasize. Same reason academic papers don't use compilable code.
    – flyinghigh
    9 hours ago






  • 1




    @flyinghigh Code Review is all about reviewing working code, not an algorithm or hypothetical code, just real, ready-to-use code. Of course you can scope the "working code" to a single function or module or whatever, but here we need the real thing, not just the idea. For the algorithm itself you may take a look at Stack Overflow or maybe Software Engineering Stack Exchange.
    – Alejandro
    8 hours ago








2




2




Welcome on Code Review. The code you presented in its current form is not meaningfully reviewable. We only review real, working code. If you edit your question to contain your actual code we can review it for improvements. See What topics can I ask about? for reference.
– Calak
9 hours ago




Welcome on Code Review. The code you presented in its current form is not meaningfully reviewable. We only review real, working code. If you edit your question to contain your actual code we can review it for improvements. See What topics can I ask about? for reference.
– Calak
9 hours ago












Wait really? Is there a better forum for this then? The algorithm is what needs to be reviewed, not working code. If anything, working code would distract from the idea that I'm trying to emphasize. Same reason academic papers don't use compilable code.
– flyinghigh
9 hours ago




Wait really? Is there a better forum for this then? The algorithm is what needs to be reviewed, not working code. If anything, working code would distract from the idea that I'm trying to emphasize. Same reason academic papers don't use compilable code.
– flyinghigh
9 hours ago




1




1




@flyinghigh Code Review is all about reviewing working code, not an algorithm or hypothetical code, just real, ready-to-use code. Of course you can scope the "working code" to a single function or module or whatever, but here we need the real thing, not just the idea. For the algorithm itself you may take a look at Stack Overflow or maybe Software Engineering Stack Exchange.
– Alejandro
8 hours ago




@flyinghigh Code Review is all about reviewing working code, not an algorithm or hypothetical code, just real, ready-to-use code. Of course you can scope the "working code" to a single function or module or whatever, but here we need the real thing, not just the idea. For the algorithm itself you may take a look at Stack Overflow or maybe Software Engineering Stack Exchange.
– Alejandro
8 hours ago















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Create new schema in PostgreSQL using DBeaver

Deepest pit of an array with Javascript: test on Codility

Costa Masnaga