


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A concise overview of essential string functions and concepts in java. It covers methods like equals(), compareto(), tolowercase(), touppercase(), charat(), and substring(), explaining their usage with examples. Additionally, it discusses exception handling and the differences between string and stringbuffer, offering insights into when to use each for efficient string manipulation. This resource is ideal for students learning java programming and seeking a quick reference guide to string operations and exception handling. (404 characters)
Typology: Schemes and Mind Maps
1 / 4
This page cannot be seen from the preview
Don't miss anything!



Question 1 equals() and ==
==
It is a method. It is used to check if the contents of two strings are same or not.
It is a relational operator. It is used to check if two variables refer to the same object in memory
Question 2 compareTo() and equals() compareTo()
the String object precedes, follows or is equal to the String argument equals() It checks if contents of two strings are same or not.The result is true if the contentsare same otherwise it is false.
Question 3
Converts all characters of the String object to lower case Example: String str = "HELLO":
STRING FUNCTION
toUpperCase() Converts all characters of the String object to upper case Example: String str = "hello":
Output of this code snippet will be HELLO.
Question 4 charAt() and substring()
It returns a character from the string at the index specified as its argument Itsreturn type is char
substring() It extracts a part of the string as specified by its arguments and returns the extracted part as a new
Its return type is String.
Question 5 What is exception? Name two exception handling blocks. An exception is an event, which occurs during the execution of a program that disrupts the normal flow of the program's instructions. Two exception handling blocks are try and catch.
Question 6
Useful String Functions: Function
Return Type int
int
int
Use
Tocount number of characters in aString
To calculate index/position of a character in a String
To calculate last occurrence of a character in a String
String a="Hello"; int b=a.length();
String a="Hello"; int b=a.indexOf('e'); Output: 1
String a="Hello"; int b=a.lastindexOf(); Output: 3
compareTolgnoreCase() int
concat()
replace()
Question 7
String
String
Question 8
To return difference of ASCIl value of unmatched characters of two Strings if cases are not same.
Tojoin two Strings without any space
To replace a character or String from a String with new one
Difference Between String and StringBuffer
String a="ABC"; String b="abc"
Which package is used for String in Java?
int c=a.compareTo(b);
String a="ABC"; String b="abc" String c=a.concat(b) Output: ABCabc String a=" India is my country";
String b=a.replace("my","our"); Output: India is our country
String operations like concat() create a StringBuffer operations are mutable and don't create new objects on
StringBuffer
modify content frequently. frequently like building a String through multiple additions.