+ 3

Variable & Placeholder difference

What is the difference between variable & placeholders. How they are used in doing.

29th Mar 2018, 5:39 PM
N1H4R
N1H4R - avatar
5 Respuestas
+ 4
Variables are named slots of memory that store data for you to use. Placeholders are something you can use in your string so you can more properly format the string in a readable way instead of constantly breaking the string by concatenating variables into place. Placeholders are just a tidier way of doing it. I threw together an example so you can see it in action. https://code.sololearn.com/cC7iM3XDZaOL/#java public class Program { public static void main(String[] args) { String user = "N1H4R"; String welcome = String.format("Welcome to SoloLearn, %s!", user); System.out.println(welcome); } } EXAMPLE WITHOUT PLACEHOLDERS: String user = "N1H4R"; String welcome = "Welcome to SoloLearn, " + user + "!"; System.out.println(welcome); ^As you can see, that's not as clean as using placeholders. With simple strings, it doesn't matter too much, but imagine that it was a whole paragraph and you needed to use multiple variables to provide dynamic content? Things can start to get messy and harder to read.
29th Mar 2018, 5:54 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 3
You're welcome! Good luck on your studies.
29th Mar 2018, 8:16 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 1
yeah ! now I got it. thanks for helping :)
29th Mar 2018, 6:17 PM
N1H4R
N1H4R - avatar
+ 1
yeah ! now I got it. thanks for helping :)
29th Mar 2018, 6:17 PM
N1H4R
N1H4R - avatar
0
yup :)
29th Mar 2018, 8:17 PM
N1H4R
N1H4R - avatar