课程: Java 8 Essential Training

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Using the String class

Using the String class

- So let's create a few strings. I'm working in the project StringClass and I'll add code to the main method. I'll declare a string that I'll name s1. And I'll assign its value with a literal. String literals are always wrapped in double quotes. And I'll assign This is a String. Then I'll output that value using System.out.println and I'll output s1. And I'll run that code and I get what's expected. This is a String. Now I'll declare a second String but this time I'll use class constructor method syntax. And I'll pass in another String literal of This is also a String. I'll duplicate and move this line down and I'll output s2. And again I get back the expected result. So again there is no functional difference between these two syntax styles. They're both creating a String object and which you use is a matter of preference. You can also create strings by concatenating or appending values together. I'll create…

内容