String Class

String Variables in Java

String variables are variables used to hold strings.


Syntax
modifier String stringName = "String to store";

Notes

A string is technically an object, so its contents cannot be changed (immutable). For mutable strings, use the StringBuffer or StringBuilder classes.

A string variable must be initialized with either a value (which will be permanent) or null (for later initialization).


Example
String name = "Anthony";
System.out.println("Hello, your name is " + name);

See Also
Related

Variable Declaration

Documentation

String Class - Java Docs

Add to Slack

< Throwing an Exception   |   String Length >

© 2018 SyntaxDB. All Rights Reserved.