By: Emiley J Viewed: 153702 times Printer Friendly Format
The literal meaning of the word String means 'something that is twisted together to form a thin length'. The verbr String means 'hang something so that it streches in a long line'. In computer programming languages, String means a datatype that is used to store some characters. A Java String is a stream of characters grouped together serially. An example String is a word "Hello" or a phrase "Hello World".
A String can be a NULL character, a single character or a word or a phrase, or an email or an entire book. Almost all computer languages store Strings similarly and represented between quotes and are a sequence of characters (Char). For example, in Java you can create a String as below
A Java String is stored in memory as below. The chars in a String are represented by index numbers. The left most character index is 0.
In the above String "Hello", the first character H is at index 0 and e is at index 1 and so on.
Since the index of a String always starts at 0, the length of a String is always 1 more than the index of the last character. In Java a String is a Class that is in the Java basic package
java.lang. Therefore, when you want to use a String in your Java program, you don't need to import specifically any particular package. Since a Java String is a Class, it comes with many useful methods that you can use to manipulate Java Strings.
A very useful and a commonly used method is length(). Quite often when you deal with Java Strings you will need to know its length. In other words you want to know how many characters are there in the String. You can do this by calling its length() method as below.
String a = "Hello";
int len = a.length(); // len is 5
Here is a list of useful sample programs that will help you in handling Java Strings in your programs
- String Concatenation using Java
- String Array in Java
- Palindrome String in Java
- concat(), replace(), and trim() Strings in Java
- String Class Constructors in Java
- String Conversion and toString() in Java
- Count number of vowels, consonants and digits in a String in Java
- indexOf() and lastIndexOf() in Java
- How to use equals() and equalsIgnoreCase() in Java
- Converting Numbers to and from Strings using Java
- Using toLowerCase() and toUpperCase() in Java
- valueOf() in Java
- Using StringTokenizer in Java
- Using substring() in Java
- compareTo( ) in Java
Most Viewed Articles (in Java )
Latest Articles (in Java)
Comment on this tutorial
- Cloud Computing
- Java Beans
- Mac OS X
- Office 365
- Tech Reviews
Subscribe to Tutorials
1. Very good article on string , please also mentions
View Tutorial By: Subham at 2014-04-29 18:01:04