String Handling Flashcards
String is available under which package
java.lang
Assigning string
- Direct assignment
- Assignment using new keyword
Char charAt(int index) does what
Returns character from given index number
What does int index of(char ch) do
Returns first occurence of character from given index number
What does string substring (int start_index) do
Extracts all characters after the given index number
Syntax of replace function
String.replace(character to replace, character to appear)
What does String 1 concat(String 2) do
Joins two strings together
What does String trim() do
Remove leading and trailing blanks from a string
What does String Boolean ends with(String s) and startsWith do?
Check if a suffix and prefix is present respectively
What does primitive type valueOf(String s) do?
Used to covert a string to primitive data type of respective wrapper class
What is StringBuffer
Another type of class with some added functionality to handle strings. You can declare object of StringBuffer type
characteristics of StringBuffer
- refers to specific length in memory to contain characters
- length can be changed using setLength() function.
- if the String has a bigger length than of StringBuffer object, then extra characters are truncated
- if string has a shorter length than StringBuffer object, extra characters such as ‘\u0000’ are in empty spaces
what is append() used for
to add a string at the end of another string
what is setCharAt(index, character) used for
replace a character with another character available at specific index of string.
what is insert(int index, String) used for
insert a String at a specified index