String In Java Example
Chapter:
Java Basics
Last Updated:
08-08-2016 19:09:55 UTC
Program:
/* ............... START ............... */
public class JavaStringExample {
public static void main(String args[]) {
char[] javaScan = { 'J', 'A', 'V', 'A', 'S', 'C', 'A', 'N' };
String helloString = new String(javaScan);
System.out.println(helloString);
}
}
/* ............... END ............... */
Output
Notes:
-
String is a sequence of characters.
- Java String provides a lot of concepts that can be performed on a string such as compare, concat, equals, split, length, replace, compareTo, intern, substring etc.
- Syntax : String greeting = "Welcome to JavaScan.com!";
- The java.lang.String class implements Serializable, Comparable and CharSequence interfaces.
- The java String is immutable i.e. it cannot be changed but a new instance is created. For mutable class, you can use StringBuffer and StringBuilder class.
Tags
Static Method, Java