All About Class StringOutOfBoundsException in Java



StringOutOfBoundsException is thrown from an application's chatAt(index i) method in class String or by other String method,when tried to access a character that is outside the boundary or the bounds of a String. This is mainly to indicate that an index is either negative ,equal to the size of the String or greater than the size of the String.

The structure of the class is given by:


public class java.lang.StringOutOfBoundsException extends java.lang.IndexOutOfBoundsException{
//constructor
public StringOutOfBoundsException();
//constructs an empty StringOutOfBoundsException object that is an object with no message specified.
public StringOutOfBoundsException(String message);
//constructs an StringOutOfBoundsException object with the message specified.
public StringOutOfBoundsException(int index);
//
//constructs an StringOutOfBoundsException object with the argument indicating the illegal index.
}
 
Example-An attempt to access a non existent character position in a String.

public void myStringMethod()
{
String myString="Love";
char myChar=myString.charAt(7);
}
 
All About Class StringOutOfBoundsException in Java All About Class StringOutOfBoundsException in Java Reviewed by Animesh Chatterjee on September 19, 2018 Rating: 5

No comments:

Powered by Blogger.