Consider the following program:
import java.util.*; public class Main { public static void main(String []args) { String hello = "hello"; String world = "world"; StringBuffer helloWorld = new StringBuffer(hello + world); List<String> list = Arrays.asList(hello, world, helloWorld.toString()); helloWorld.append("!"); list.remove(0); // REMOVE System.out.println(list); }//from w w w .j a v a 2s .co m }
Which one of the following options is correct?
helloworld
]helloworld!
]helloworld
]b)
The Arrays.asList()
method returns a List object that is backed by a fixed-length array.
You cannot modify the List object returned by this array, so calling methods such as add()
or remove()
will result in throwing an UnsupportedOperationException.