Question Answer Java Code Example What is a ConcurrentModification Exception? It occurs when one attempts to modify a collection while iterating over it. List<String> list = new ArrayList<>(Arrays.asList("one", "two")); for(String s : list) { list.remove(s); } This will throw ConcurrentModificationException How can you invoke a method using the Reflection API? The Reflection API allows invoking a method using the invoke method. Java Class<?> clazz = String.class; Method method = clazz.getMethod("substring", int.class); String str = "hello"; String result = (String) method.invoke(str, 2); System.out.println(result); // llo What is a Record? In Java, a record is a type declaration that defines a transparent carrier for immutable data. It can be thought of as a nominal tuple. Java record Person(String name, int age) {}; Person person = new Person("John", 25); System.out.println(person.name()); What is an atomic variab...
Comments
Post a Comment