Online Tutorials & Training Materials | STechies.com
Register Login
Advertisement

Java String Introduction and Uses

|| 0

Java String Introduction and Uses
Stechies

Creating String Object in Java Programming

This tutorial gives a short explanation about definition and uses of String variable in Java Programming.

Definition of String

Strings are a sequence of characters, for example, Delhi, Ankit, how are you etc. String are treated as the object which means string is the pre-defined class in JAVA library.

Note: Strings are are not primitive type variables they are reference type variable in JAVA.

Creating a variable to store String

public class Names

public static void main(String[] args) {

String name = "ankit"; //creating a object to store a string value//

System.out.println(name);

}}

Output = ankit

String Concatenation

String Concatenation is used to join string variable with other varaible. This can be done by using plus(+) operator but in order to join the string we should atleast have one operand of string type.

public class Names

public static void main(String[] args) {

String name = "ankit"; //creating a object to store a string value//

System.out.println(name+22);

}}

Output = ankit24

We can also use (+=) operator to concatenate the string

public class Names

public static void main(String[] args) {

String name = "ankit"; //creating a object to store a string value//

name += "vaibhav";

System.out.println(name);

}}

Output = ankitvaibhav

Converting String to Upper Case

public class lion

public static void main(String[] args) {

String name = "ankit"; //creating a object to store a string value//

name += "vaibhav";

name = name.toUpperCase(); //using method to convert string to uppercase//

System.out.println(name);

}}

Output = ANKITVAIBHAV

 


Related Articles

Advertisement
Advertisement
Advertisement