Java : ArrayStoreException with Examples
ArrayStoreException (Java SE 20 & JDK 20) API Examples.
You will find code examples on most ArrayStoreException methods.
Summary
String[] strings = new String[]{"aaa", "bbb", "ccc"};
System.out.println(Arrays.toString(strings)); // [aaa, bbb, ccc]
Object[] objects = strings;
objects[0] = "XXX";
objects[1] = "YYY";
System.out.println(Arrays.toString(strings)); // [XXX, YYY, ccc]
try {
objects[2] = Integer.valueOf(123);
} catch (ArrayStoreException e) {
System.out.println("ArrayStoreException! : " + e.getMessage());
}
// Result
// ↓
//ArrayStoreException! : java.lang.Integer
Please see also Java Language Specification :
Constructors
ArrayStoreException ()
final var e = new ArrayStoreException();
System.out.println(e); // java.lang.ArrayStoreException
ArrayStoreException (String s)
final var e = new ArrayStoreException("abcde");
System.out.println(e); // java.lang.ArrayStoreException: abcde
System.out.println(e.getMessage()); // abcde
Methods declared in Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
Please see the link below.
Related posts
- API Examples
- Error
- Exception
- RuntimeException
- ArithmeticException
- ArrayIndexOutOfBoundsException
- CancellationException
- ClassCastException
- ConcurrentModificationException
- DateTimeException
- DateTimeParseException
- IllegalArgumentException
- IllegalStateException
- IndexOutOfBoundsException
- NoSuchElementException
- NullPointerException
- PatternSyntaxException
- StringIndexOutOfBoundsException
- UnsupportedOperationException
- Throwable