I know this is basic and most people here
do know this, and how to create string's, but it's for people who are new to java and didnt know this.
Alright, a string is basically a sequance of characters, they are mostly used for messages in java, a prime example would be the hello world program, such as the message: "Hello, World!" which is displayed in the helloApp.
In java, string's are pretty wierd, they do not define strings as a primitive type, but instead strings are the referance type defined by the java API String class.
I am know goin to talk to you about how these string are used.
Java's string-handling features are pretty advanced and fun to learn.
Strings are declared and initialized much like primiative types like i said before, well im know going to show you the difference the only actually diffrence is the word "String" is capitlezed unlike the keywords for the primitive types such as int and double etc....
The reason for that is String isnt actually a keyword, instead it's the name of the Java API class that provides for string objects.
The following statements define and initilize a string variable:
String s;
s = "Hello, Wolrd!";
in this case the variable names "s" of type String is declared and initilized with the String statment
"Hello, World!", please notice that string laterals are enclosed un quotation marks, not apostrophes so dont make the silly mistake people do.
Apostrophes are used for character literals, please note* these are diffrent from string literals.
Like any varible declaration, a string declaration can include an initilizertherefore you can declare and initilize a string varible in one statement, like this:
String s = "Hello, Wolrd!";
Class varabiles and instance varibles are automatically initilzed to empty strings, but local varables are not duh..
alright im now gona show you how to initilize a local string varible to an emptey string, use a statement like this:
String s = " ";
Combining StringsCombining two strings can be done by using the Plus sign (+), this is the
Concatenation operator.
I am now going to give you an example using the hello world app.
String hello = "Hello, ";
String wolrd = "World!";
String greeting = hello + world;
I hope you have learnt something new if you feel i have made a spelling mistake or an error please let me know, thanks
Ikram