String

Strings are a Sequence of Characters widely used in Java Programming.A Java String Contains an immutable Sequence of Unicode Characters. Unlike C/C++, where String is Simply an Array of Char, A Java String is an Object of the Class java.lang.

Unlike an Ordinary Class ,Java String is special

String is associated with String literal in the form of Double-Quoted Texts Such as "Hello MyJava!".The '+' Operator is Overloaded to Concatenate two String Operands.String is immutable.

Creating String »

The most direct way to create a String is :

➯ String CreateString = "Hello MyJava!";
In this case, "Hello MyJava!" is a string literal—a series of characters in code that is enclosed in double quotes.

Example of String :-

  
    
   class StringDemo 
			{
           public static void main(String[] args) 
           {
        System.out.println("Hello MYJava!");
				}
			}
    


➯ The other ways of create String objects are by using the new keyword and a constructor. The String class has thirteen constructors that allow to provide the initial value of the string

String Class Constructors:


String()
➯ Initializes a newly created String object so that it represents an empty character sequence.

String(byte[] bytes)
➯ Constructs a new String by decoding the specified array of bytes using the specified charset.

String(byte[] bytes, int offset, int length)
➯ Constructs a new String by decoding the specified subarray of bytes using the platform's default charset.

String(byte[] bytes, int offset, int length, Charset charset)
➯ Constructs a new String by decoding the specified subarray of bytes using the specified charset.

String(byte[] bytes, int offset, int length, String charsetName)
➯ Constructs a new String by decoding the specified subarray of bytes using the specified charset.

String(byte[] bytes, String charsetName)
➯ Constructs a new String by decoding the specified array of bytes using the specified charset.

String(char[] value)
➯ Allocates a new String so that it represents the sequence of characters currently contained in the character array argument.

String(char[] value, int offset, int count)
➯ Allocates a new String that contains characters from a subarray of the character array argument.

String(int[] codePoints, int offset, int count)
➯ Allocates a new String that contains characters from a subarray of the Unicode code point array argument.

String(String original)
➯ Initializes a newly created String object so that it represents the same sequence of characters as the argument; in other words, the newly created string is a copy of the argument string.

String(StringBuffer buffer)
➯ Allocates a new string that contains the sequence of characters currently contained in the string buffer argument.

String(StringBuilder builder)
➯ Allocates a new string that contains the sequence of characters currently contained in the string builder argument.

String Methods »

Methods used to obtain information about an object are known as Accessor Methods. String Class has following Methods :

  • ➢ charAt(int index)
  • ➢ codePointAt(int index)
  • ➢ codePointBefore(int index)
  • ➢ codePointCount(int beginIndex, int endIndex)
  • ➢ compareTo(String anotherString)
  • ➢ compareToIgnoreCase(String str)
  • ➢ concat(String str)
  • ➢ contains(CharSequence s)
  • ➢ contentEquals(CharSequence cs)
  • ➢ contentEquals(StringBuffer sb)
  • ➢ copyValueOf(char[] data)
  • ➢ copyValueOf(char[] data, int offset, int count)
  • ➢ endsWith(String suffix)
  • ➢ equals(Object anObject)
  • ➢ equalsIgnoreCase(String anotherString)
  • ➢ format(Locale l, String format, Object... args)
  • ➢ format(String format, Object... args)
  • ➢ getBytes()
  • ➢ getBytes(Charset charset)
  • ➢ getBytes(String charsetName)
  • ➢ getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
  • ➢ hashCode()
  • ➢ indexOf(int ch)
  • ➢ indexOf(int ch, int fromIndex)
  • ➢ indexOf(String str)
  • ➢ indexOf(String str, int fromIndex)
  • ➢ intern()
  • ➢ isEmpty()
  • ➢ lastIndexOf(int ch)
  • ➢ lastIndexOf(int ch, int fromIndex)
  • ➢ lastIndexOf(String str)
  • ➢ lastIndexOf(String str, int fromIndex)
  • ➢ length()
  • ➢ matches(String regex)
  • ➢ offsetByCodePoints(int index, int codePointOffset)
  • ➢ regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)
  • ➢ regionMatches(int toffset, String other, int ooffset, int len)
  • ➢ replace(char oldChar, char newChar)
  • ➢ replace(CharSequence target, CharSequence replacement)
  • ➢ replaceAll(String regex, String replacement)
  • ➢ replaceFirst(String regex, String replacement)
  • ➢ split(String regex)
  • ➢ split(String regex, int limit)
  • ➢ startsWith(String prefix)
  • ➢ startsWith(String prefix, int toffset)
  • ➢ subSequence(int beginIndex, int endIndex)
  • ➢ substring(int beginIndex)
  • ➢ substring(int beginIndex, int endIndex)
  • ➢ toCharArray()
  • ➢ toLowerCase()
  • ➢ toLowerCase(Locale locale)
  • ➢ toString()
  • ➢ toUpperCase()
  • ➢ toUpperCase(Locale locale)
  • ➢ trim()
  • ➢ valueOf(boolean b)
  • ➢ valueOf(char c)
  • ➢ valueOf(char[] data)
  • ➢ valueOf(char[] data, int offset, int count)
  • ➢ valueOf(double d)
  • ➢ valueOf(float f)
  • ➢ valueOf(int i)
  • ➢ valueOf(long l)
  • ➢ valueOf(Object obj)
share on :        :  

Love to hear your Views / Guidance / Recommendations on this Post…

Explore the Technology World

The mind behind Linux & GIT : Linus TorvaldsLinus Torvalds transformed technology twice — first with the Linux kernel, which helps power the Internet, and again with Git, the source code management syst ...Read MoreTensorflow and deep learningWith Tensorflow ,deep machine learning transitions from an area of research into mainstream software engineering. ...Read MoreJava program to return all possible permutations from collection of distinct numbersexample of Java program to return all possible permutations from collection of distinct numbers ...Read MoreReal Time Analytics with Spring Application Development FrameworkSpring is the most popular application development framework for enterprise Java.Millions of developers use Spring to build simple, truly portable, fast and fle ...Read MorePath Setting in Java When an application is launched from command prompt Windows OS searches for the executable program in the current working directory. The prompt throws an error ...Read MorePicture-in-Picture App for Android devices with Source CodePicture-in-Picture is a special type of multi-window mode mostly used for video playback for Android devices.Released under Apache License 2.0 , which means you ...Read MoreFacebook |Google+ | Twitter | LinkedIn | Youtube About | Cookies-Policy | Disclaimer | Site Map | Contact

Call / Visit for New Batch

Services

Why Join Us

  • ➯ Free Demo Classes
  • ➯ No Registration Fee
  • ➯ Interview Questions
  • ➯ Study Materials
  • ➯ Softwares
  • ➯ Aptitude & Reasoning
  • ➯ Placement Assitance

Address

  • MyJava Training Institute ,
  • Plot No.243 , shop No 14 ,
  • Secnd Floor , Zone-II ,
  • M.P.Nagar , Bhopal,
  • Madhya Pradesh ( 462011 )
  • ☎  08871209400 , 7987028543
  • 🌐 www.myjava.in
FacebookGoogle +TwitterYouTube

MyJava - java Training Institute