Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,690 --> 00:00:02,850
We can use the string type to store text.
2
00:00:05,150 --> 00:00:10,100
So far, we played around with Int variables also every time you update the passengers variable, the
3
00:00:10,100 --> 00:00:15,620
ministry wanted you to print it, which we did, but our print statements were a bit boring in the sense
4
00:00:15,620 --> 00:00:18,620
that it would be nice if each message came with some text.
5
00:00:19,490 --> 00:00:25,460
For example, I'd rather print the number of passengers is nine, four or zero instead of just printing
6
00:00:25,460 --> 00:00:26,600
plain old numbers.
7
00:00:29,370 --> 00:00:33,270
So in this lesson, you're going to use the string type to store and update text.
8
00:00:39,210 --> 00:00:42,780
String pretty much means text, so why is it called string?
9
00:00:42,990 --> 00:00:44,010
That's a pretty rare name.
10
00:00:44,880 --> 00:00:49,140
Well, think about a character is anything that you can type through your keyboard, like the letter
11
00:00:49,140 --> 00:00:51,960
A, B or C, now the name string.
12
00:00:51,960 --> 00:00:57,330
It makes sense if you think about text as something that strings together a bunch of characters.
13
00:01:00,930 --> 00:01:07,080
OK, and there are three things we need to define a string variable, there is the string type such
14
00:01:07,080 --> 00:01:13,800
that this variable named sentence can only store string value and the string value is just text wrap
15
00:01:13,800 --> 00:01:14,730
and double quotes.
16
00:01:18,010 --> 00:01:24,430
All right, inside the bus class, make a searing variable named sentence, string sentence is equal
17
00:01:24,430 --> 00:01:32,410
to and in double quotes, will the right number of passengers put a colon with an empty space at the
18
00:01:32,410 --> 00:01:32,740
end?
19
00:01:40,090 --> 00:01:44,320
And print the value system, dart out.
20
00:01:45,180 --> 00:01:48,690
Dot print, line sentence.
21
00:01:55,340 --> 00:01:56,630
Compile the codes.
22
00:02:01,950 --> 00:02:03,540
And run, runit.
23
00:02:07,770 --> 00:02:13,980
And the sentence variable story is a tax value, which you printed using the print online function,
24
00:02:14,250 --> 00:02:19,680
the easy stuff, but right now the sentence isn't finished in the sense that we need to connect the
25
00:02:19,680 --> 00:02:22,800
passengers value at the end of the string after each update.
26
00:02:23,670 --> 00:02:25,320
We want to achieve something like this.
27
00:02:27,860 --> 00:02:30,770
So for now, remove the first print lights stem and it's pretty useless.
28
00:02:32,790 --> 00:02:37,980
And we're going to come back to this class because right now we're going to make a separate class where
29
00:02:37,980 --> 00:02:39,480
we learn how to join strength's.
30
00:02:42,270 --> 00:02:49,200
So inside the section to project make a new file named Joining Strings Java and the Joining Strings
31
00:02:49,200 --> 00:02:50,940
class must have the main method.
32
00:03:00,270 --> 00:03:03,060
OK, you can join string values with the plus simple.
33
00:03:06,530 --> 00:03:11,910
This involves text added to more text, and the result is a joint text.
34
00:03:12,620 --> 00:03:13,700
It's pretty simple, really.
35
00:03:13,700 --> 00:03:19,370
Joining strong values is common if you need to connect a placeholder, a small piece of text as part
36
00:03:19,370 --> 00:03:20,720
of a longer sentence.
37
00:03:21,500 --> 00:03:24,920
So inside the joining strings class, make a variable named sentence.
38
00:03:25,490 --> 00:03:27,200
String sentence.
39
00:03:28,740 --> 00:03:31,630
Is equal to in double quotes.
40
00:03:31,650 --> 00:03:33,990
His name is.
41
00:03:35,080 --> 00:03:37,420
With a colon and empty space at the end.
42
00:03:41,220 --> 00:03:44,370
Never going to make another variable named Placeholder String.
43
00:03:46,280 --> 00:03:47,210
Placeholder.
44
00:03:49,090 --> 00:03:52,780
Is equal to in double quotes, Harry.
45
00:03:57,700 --> 00:04:04,720
Now, using the plus sign, you can connect the two string values and print them system dot out.
46
00:04:05,710 --> 00:04:11,740
Dot print line, we're going to connect the sentence value to our placeholder.
47
00:04:14,440 --> 00:04:15,730
Compile the code.
48
00:04:21,050 --> 00:04:22,640
And run, runit.
49
00:04:28,770 --> 00:04:31,060
His name is Harry Nice.
50
00:04:31,990 --> 00:04:35,580
So first off, the sentence variable store is a tax value.
51
00:04:38,210 --> 00:04:44,180
The placeholder store is a tax value as well, and you were able to join both values and printed them.
52
00:04:48,480 --> 00:04:55,020
You can also join a string value with an integer using the plus symbol and connecting a number to the
53
00:04:55,020 --> 00:04:56,730
end of a string is very common.
54
00:04:58,580 --> 00:05:06,980
This involves text the plus icon and a number and what happens is pretty cool, the number blends into
55
00:05:06,980 --> 00:05:07,580
the strich.
56
00:05:10,030 --> 00:05:11,720
So we're going to test this in Java.
57
00:05:11,770 --> 00:05:17,290
Let's create two more variables and points is equal to 50.
58
00:05:22,460 --> 00:05:29,870
String announcement is equal to and I'm going to start this thing off with empty space and then follow
59
00:05:29,870 --> 00:05:33,590
it up with points for Gryffindor.
60
00:05:38,190 --> 00:05:48,060
All right, now print those two variables is one system, dot out, dot print, nine points plus announcement.
61
00:05:53,870 --> 00:05:55,040
Compile the code.
62
00:05:56,330 --> 00:06:04,520
Well, that was a word glitch and run it and 50 points for Gryffindor, the result is a complete sentence.
63
00:06:05,150 --> 00:06:09,710
The points variable stores a number, the announcements, variable stores text.
64
00:06:10,220 --> 00:06:12,050
Then you added both variables.
65
00:06:12,050 --> 00:06:17,960
And when you do that, the number blends into the string, and that is Java embeds the number inside
66
00:06:17,960 --> 00:06:18,470
the string.
67
00:06:21,880 --> 00:06:26,890
OK, back to the bus with this knowledge, I believe you can confidently wrap up the bus application
68
00:06:27,670 --> 00:06:31,840
every time we update the number of passengers, we're going to print the new value as part of a longer
69
00:06:31,840 --> 00:06:32,490
sentence.
70
00:06:33,280 --> 00:06:34,750
So we'll say sentence.
71
00:06:37,850 --> 00:06:42,530
Plus, passengers, and we're going to copy this two more times.
72
00:06:48,210 --> 00:06:49,620
We're in a compile the codes.
73
00:06:57,020 --> 00:07:02,570
And this looks pretty good after each update, you printed a string of that connect sentence to the
74
00:07:02,570 --> 00:07:07,220
number of passengers and the ministry is more than happy with your work.
75
00:07:07,220 --> 00:07:08,080
They're delighted.
76
00:07:09,160 --> 00:07:12,970
All right, there's just one last thing I want to go over, just like we updated variables, you can
77
00:07:12,970 --> 00:07:14,680
also update string variables.
78
00:07:15,790 --> 00:07:22,930
So we'll say sentence is equal to in double quotes, end of shift.
79
00:07:24,480 --> 00:07:30,450
Test them, dart out, dart print line sentence.
80
00:07:32,740 --> 00:07:34,150
Rolnik and Palakkad.
81
00:07:44,960 --> 00:07:49,190
All right, the central stores in your valley, which we printed at the end of the driver's shift,
82
00:07:49,490 --> 00:07:54,230
although you know what, instead of updating the sun's variable, it's more concise than just print
83
00:07:54,230 --> 00:07:55,580
and shift directly.
84
00:08:01,450 --> 00:08:04,300
OK, I think our app is now complete.
85
00:08:06,380 --> 00:08:11,620
There is one last note I want to leave you with when joining string values, don't forget Whitespace.
86
00:08:12,560 --> 00:08:15,680
If you look at the code, notice that I leave whitespace in my strings.
87
00:08:16,400 --> 00:08:19,220
If you don't leave whitespace, your sentences are going to look awkward.
88
00:08:19,940 --> 00:08:22,220
Must try to remove the white space here.
89
00:08:27,110 --> 00:08:28,820
Now, I'm going to rerun the code.
90
00:08:37,530 --> 00:08:42,320
As you can see, this looks pretty bad and awkward, Java doesn't add white space for you.
91
00:08:42,360 --> 00:08:47,460
You need to do it yourself either by connecting in white space between the two variables.
92
00:08:48,900 --> 00:08:50,760
So we're going to compile the code and run that.
93
00:08:54,210 --> 00:09:01,350
This works just fine besides white space in between the two strings and connect everything, but I prefer
94
00:09:01,350 --> 00:09:05,190
my method where I just leave some white space inside the string value.
95
00:09:05,820 --> 00:09:07,170
So now remove those.
96
00:09:11,160 --> 00:09:14,190
And leave whitespace here in here.
97
00:09:15,750 --> 00:09:21,060
And both methods are fine, but honestly preferred this one, I find it easier to just add whitespace
98
00:09:21,060 --> 00:09:24,390
inside the string as opposed to adding an externally.
99
00:09:27,380 --> 00:09:32,810
In this lesson, you learned about string variables, string variables allow you to store text and you
100
00:09:32,810 --> 00:09:36,260
define two string variables is that each one stored a text value.
101
00:09:37,150 --> 00:09:43,040
You learn to join both string values with the plus symbol, but sometimes you need to connect a string
102
00:09:43,040 --> 00:09:47,780
with a number and the plus operator can be used to blend the number inside a string.
10050
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.