Concatenation hell with traditional string literals

The following is an alternative that is meant to make the preceding code readable, by defining parts of the string value on multiple lines. However, when doing so, you should use multiple string concatenation operators (+) and string delimiters ("):

String html =  "<HTML>" + 
"
	" + "<BODY>" + 
"
		" + "<H1>Meaning of life</H1>" + 
"
	" + "</BODY>" + 
"
" + "</HTML>";

I would prefer to add whitespaces to the preceding code, to make it more readable:

String html =  "<HTML>" + 
                    "
	" + "<BODY>" + 
                        "
		" + "<H1>Meaning of life</H1>" + 
                    "
	" + "</BODY>" + 
                "
" + "</HTML>"; 

Although the preceding code looks better in terms of readability, it delegates a lot of responsibility to the programmer, to insert whitespaces in the correct places. As a quick note, the whitespaces (outside of the double quotes) aren't a part of the variable HTML; they just make it readable. As a developer, it's a pain to write such code.

The Java GUI library doesn't work with the control characters, such as the newline. So, this approach can be used with GUI classes.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.198.174