Member-only story
Hi everyone, welcome back. In these examples, we will be going over Strings in Java. A string variable is used to hold a collection of characters, which can be used to save text. We will be going over some common functions regarding strings that you may find to be helpful. With this introduction out of the way, let’s get into it.
Creating a String
Let’s start by creating a string. See the example below:
String myString = "Text";
Sweet, now that we have that, we can now start performing a number of string related functions on it.
Check String Size
Now, let’s see how we can check the size of the string, or in other words, how many characters are in the string. We can do this by using the length() function. Let’s see an example:
String myString = "Text";
System.out.println(myString.length());Output:
4
In the example above, we can see that we used the length() function on our string and printed the result. We can see that we are successfully retrieving the size of our string by checking the output.