Java - Creating Strings [Digg.com This!]
Although String acts like a class, it is in fact considered a primitive variable type.
To create an empty string we can do:
String mystr;
To create a string with something in, we can do:
String mystr2 = new String("This is my text.");
~~~
Strings also have other useful abilities, like being able to be added:
String s1, s2, result;
s1 = "Hello";
s2 = " there.";
result = s1 + S2;
Meaning if we print result using System.out.println we would get:
Hello there.
Numbers can also be added in the same way:
String str, result2;
str = "Two: ";
result = str + 2;
Resulting in:
Two: 2



0 Comments:
Post a Comment
<< Home