Reputation: 17269
Let say I have to used a two paragraph string in my java program. What would be the best approach on this? Should the paragraph saved in a file and retrieved when used? Or there are better approach?
Upvotes: 0
Views: 269
Reputation: 106470
The only time I've seen a String with that kind of length on it would be in internationalized property files. This keeps them separate from logic, and make editing the paragraph/necessary code simpler.
In short, yes, the better approach would be to store the String in its own separate file. However, there shouldn't be any reason to have one that long - even with property files, it's better to break those out too.
Upvotes: 0
Reputation: 3016
and just to add if u need concatenate these two paragraph strings together a better approach is to use the StringBuffer class and append them.
Upvotes: 1
Reputation: 993951
It depends. If the paragraphs will never change, then it might make sense to embed them directly in the source code. This has the advantage that no extra files are needed to run your code.
If you expect that the paragraphs might change, it's probably better to put them in an external file because that allows somebody to modify the text without having to recompile the program. This could be beneficial if those who modify are not programmers.
Upvotes: 2