Assuming that you are writing the source and make variables that you use many times. Let's make constants for "fixed" "character strings" that are used many times. [Constants are variables whose values cannot be changed. It becomes a constant by specifying the final modifier]
Reason: If a correction is made later, you only have to fix one place. Because the readability of the source increases I don't want to change the value I don't want to change
Method of constantization: Declare the final constant first, even if you assign a value when you declare it. You can assign the value later, but you can't change the value after you assign it.
Declare a constant again [Variable name is ... all uppercase] (Use _ (underscore) to reconnect multiple words)
String inputWords = "aiueo";
⇒ final String INPUT_WORDS = "aiueo";
⇒ static final String INPUT_WORDS = "aiueo";
Memo: If you define a constant, memory will be allocated. Cannot be included in for (it will be called many times)
Constants are defined outside the method (main is the method ☆)
By adding static, you can write to the VM and call it from there. It doesn't use much memory, so let's define it with static final ♪
Only fixed ones are made constant. Don't change the value!
Recommended Posts