I would like to store a series of "Strings" in a separate class (Constants.java) for organizational purposes.
Constants.java:
public static final String qualification1 = "'Priority' = \"" + priority + "\" AND 'Status' = \"In Progress\" AND 'Assignee' = \"" + assigneeInput + "\"";
...
In my main application class I would like to call these from from above
Main.java:
// Examples to show that these variables are dynamic
String assigneeInput = soapResponseAssignee.getSOAPBody().getTextContent();
String[] priorityList = {"Low", "Medium", "High", "Critical"};
for (String priority : priorityList) {
String qualification = RemedyConstants.qualification1;
String qualification = RemedyConstants.qualification2;
String qualification = RemedyConstants.qualification3;
...
}
The problem is that the Strings provided to my Main class tend to have variables in them, i.e. priority or assigneeInput, which are defined there. If I store the strings elsewhere, i.e. Constants.java, I will not actually be using the Strings that I want. How can I provide the strings that I want while referencing those variables in their appropriate context?
Propertiesfiles. Step 2 create a.propertiesfile. Step 3) store strings in the.propertiesfile using{0}...{n}placeholders. Step 4) create a utility class (like yourConstants) that has agetString(String key, Object... arguments). Step 5) implement the method usingPropertiesandMessageFormat.format. Step 6) Add a caching layer for theMessageFormatinstances if required. Step 7) profit.