
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
How to generate an UnsupportedOperationException in Java?
An UnsupportedOperationException is a subclass of RuntimException in Java and it can be thrown to indicate that the requested operation is not supported. The UnsupportedOperationException class is a member of the Java Collections Framework. This exception is thrown by almost all of the concrete collections like List, Queue, Set and Map.
Syntax
public class UnsupportedOperationException extends RuntimeException
Example
import java.util.*; public class UnsupportedOperationExceptionTest { public static void main(String[] args) { List aList = new ArrayList(); aList.add('a'); aList.add('b'); List newList = Collections.unmodifiableList(aList); newList.add('c'); } }
In the above example, it will generate an UnsupportedOperationException. In order to avoid this, we need to use the object of the collection rather than using the view object for modification.
Output
Exception in thread "main" java.lang.UnsupportedOperationException at java.util.Collections$UnmodifiableCollection.add(Collections.java:1055) at UnsupportedOperationExceptionTest.main(UnsupportedOperationExceptionTest.java:9)
- Related Articles
- Java Program to generate n distinct random numbers
- How to rethrow an exception in Java?\n
- How to solve an IllegalArgumentException in Java?\n
- How to generate large random numbers in Java?
- An Interesting Method to Generate Binary Numbers from 1 to n?
- How many ways to synchronize an ArrayList in Java?\n
- How to generate a random BigInteger value in Java?
- How to use an ArrayList in lambda expression in Java?\n
- Java Program to generate a random number from an array
- How to use an enum with switch case in Java?\n
- How to handle an exception using lambda expression in Java?\n
- How to convert a String to an InputStream object in Java?\n
- Generate an even squares between 1 to n using for loop in C Programming
- How to generate random values that won’t repeat in Java
- How to generate prime numbers using lambda expression in Java?

Advertisements