Strings

Strings
String ConstructorsThe String class supports several constructors. To create an empty String, you call the default constructor. For example,

1)  String s = new String();
2)  Char chars[ ] = { ‘a’, ‘b’, ‘c’ };
String s = new String(chars);
3)  String(char chars[ ], int startIndex, int numChars)
Here, startIndex specifies the index at which the subrange begins, and numChars
specifies the number of characters to use. Here is an example:
4)  Char chars[ ] = { ‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’ };
String s = new String(chars, 2, 3);
5)  String(String strObj)

String Methods

[ws_table id=”2″]

StringBuffer

StringBuffer represents growable and writeable character sequences. StringBuffer may have characters and substrings inserted in the middle or appended to the end. StringBuffer will automatically grow to make room for such additions and often has more characters preallocated than are actually needed.

StringBuffer Constructors
StringBuffer defines these three constructors:

  • StringBuffer( )
  • StringBuffer(int size)
  • StringBuffer(String str)
StringBuffer Methods

[ws_table id=”3″]




Welcome Back!

Login to your account below

Retrieve your password

Please enter your username or email address to reset your password.