Computer Science, asked by zain786, 1 year ago

what is string in blue j

Answers

Answered by riteshsheoran
1
that was programming coded language software

that about:-
BlueJ programs using String Functions In my previous post, I have discussed about the basic String class functions. Today’s post is again on String class functions :

1. Function prototype is int compareTo(String str1) - this function is normally used for sorting purpose. This function is invoked on one string and takes another string as argument. If both are same, the function returns numeric 0. If the invoking string is greater than the argument string, it returns greater than 0 and it returns less than 0 for the reverse. Actually for unequal string the function return the ASCII difference of the invoking string character and the argument string character. This is a case sensitive function.

2. Function prototype is int compareToIgnoreCase(String str1) - Same as the above excepting this function is not case sensitive. So “BURDWAN”. compareToIgnoreCase (“burdwan”) will return 0.

3. int indexOf () – This function is used to search a string or character from the invoking string. If the search is successful it returns the first occurrence location of the sub string or character within the invoking string otherwise returns -1. This function has several overloaded versions.

Function prototype : int indexOf (String str)- it returns the first occurrence location of the sub string ‘str’ within the invoking string.

Function prototype : int indexOf (char ch)- it returns the first occurrence location of the character ‘ch’ within the invoking string.

Function prototype :int indexOf (String str, int index)- it returns the first occurrence location of the sub string ‘str’ after the specified location ‘index’ within the invoking string.

Function prototype : int indexOf (char ch, int index)- it returns the first occurrence location of the character ‘ch’ after the specified location ‘index’ within the invoking string.

String substring () is a function of String class which can return a portion of the invoking string. This function has two overloaded versions.

Function prototype :String substring(int index) - this function returns the sub string of the invoking string starting from the location ‘index’ to end of the string.

Function prototype :String substring(int start, int end) - this String class function returns the sub string of the invoking string starting from the location ‘start’ to the location ‘end’ of the string.

5. We can concatenate two strings using String concat () function.
Function prototype :is String concat(String str1);
This function takes one string as argument and is invoked on another string, resulting a new string where the argument string is appended to the end of the invoking string

String str=”This is ”;
String str1=str.concat(“Burdwan”);
System. out.println(str1);
Output will be : This is Burdwan

String replace () is another function of String class which is used to replace any specified character of the invoking string with another character.
Function prototype : String replace(char ch1, char ch2);
This function takes two characters as argument. The first character is replaced with the second character of the invoking string and will generate a new string object.

String s1=”Hello”;
String s=s1.replace(‘l’,’b’);
Now the value of s would be Hebbo

7.String trim () is used to remove any leading or trailing spaces from the invoking string object.

String str=” ChakraInfotech “.trim();
Now the value of ‘str’ will be: ChakraInfotech

8. To change the case of characters in a string we can use the function String toUpperCase () and String toLowerCase ().

Function prototype :String toUpperCase () - converts all the lower case characters in a string to upper case and the upper case characters will remain unchanged.

Function prototype : String toLowerCase () is just the opposite of the above function.

This page is on String functions. If you have any doubt in any program, pl. feel free to put your comments. I am here to clear your doubts.

Answered by aditya17parthiban
0

Answer:

A string is a data type in blue j that is used to store any number (e.g 1,2,3) or any character (e.g. 1, * , a) or any statement (e.g. Hello) or a combination of everything (e.g. Hello 1*a).

Explanation:

Similar questions