Question: Java The following class is given: import java.util.Arrays; public class StringImproved { / * * * Field Detail * The storage for the characters in

"Java
The following class is given:
import java.util.Arrays;
public class StringImproved {
/**
* Field Detail
* The storage for the characters in the StringImproved class
*/
private char[] charArray;
//Initialize storage string
public StringImproved(int size){
if(size <1){
System.out.println(""Size should be a positive number"");
}
charArray = new char[size];
}
public static void main(String[] args){
// TODO Auto-generated method stub
StringImproved stringImproved = new StringImproved(5);
System.out.println(stringImproved.append(""abcde""));
System.out.println(stringImproved);
}
}
Write the following methods for the class:
1) lastIndexOf
public int lastIndexOf(char ch)
Find the last instance of the character in the StringBuffer.
Difficulty 3/10
Parameters:
ch - The character to search for.
Returns:
The index of the last instance of the nominated character, -1 otherwise.
2) length
public int length()Returns the length of the string. The length of the string is t XU06 he number of characters, digits, and punctuation, including space,
in the string. For example, ""Hello"" has a length of 5, and ""Hello world."" is length 12.
Difficulty: 1/10
Returns:
The length of the string. -1 in the event of an error.
3) prepend
public boolean prepend(java.lang.String newString)
Prepend the nominated string to the StringImproved object.
Difficulty 1/10(if you are clever)
Parameters:
newString - The string to append.
Returns:
true if successful, false otherwise."

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!