![]() > Which function is it? Are they referring to. > When you're working with StringBuilder, would the return type of the function be StringBuilder? So I can say string message = this hey y'all, and then I do whatever I want. You can even, when you define the type, you would even define that as string. > Is text blocks, are they similar to strings, do they have the same split and all that kind of stuff? We talked about string builder, and then we also talked about text blocks. So the preferred convention is start the three lines, add any text you need in the three quotes on its own new line, right? All right, so that is it for text, so we talked about strings. So I move the text to a new line, this is legal, but this is also not the preferred way. But yeah, you cannot have the opening and closing on the same line. ![]() So this doesn't really make sense to have this one line in a text block versus just a regular string. Some rules, you cannot open and close a text block all on the same line, right? They're really supposed to be for multi-line text anyway. So that's text blocks, they work pretty much like strings, other than how they're defined here. It's just nice and clean, and I can actually read this JSON now. Now, I don't have the new line characters, I don't have the plus signs, I don't have to escape any quotes. It's absolute nightmare to deal with, all right? So text blocks allows you to cleanly define multi-line strings by using three quotation marks to open and to close. And so, each one of those, I would have to put a slash in front of it. And then these ugly plus signs, I would need to escape any quotes, so you know JSON has quotes, for the key part. I would have to, one, add all of these new line characters, so that \n is a new line character, after each line. Let's say you had a JSON response that you wanted to represent in the string. But yeah, text can be pretty ugly to work with in Java, especially when it's multi-line. Let's talk about text blocks, which are basically used to work with multi-line strings, all right? And this is also something that's relatively new to the Java language, maybe a year or two old.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |