Java Vector toArray() MethodThe toArray() Java Vector class method is used to get an array containing all of the elements in this vector in the correct order. There is two different types of Java toArray() method which can be differentiated depending on its parameter. These are:
toArray() Method:This method is used to return an array which contains all of the elements in this vector in the correct order. toArray(T[] arr) Method:This method is used to return an array which contains all of the elements in this vector in the correct order. The runtime type of the returned array is that of the specified array. SyntaxFollowing is the declaration of toArray() method: Parameter
ReturnThe toArray() method returns an array containing all of the elements in the given collection. ExceptionsNullPointerException- This method has thrown an exception if the specified array is null. ArrayStoreException- This method has thrown an exception if the runtime type of arr, <T>, is not a supertype of the runtime type, <E>, of every element in this vector. Compatibility VersionJava 1.2 and above Example 1Test it NowOutput: Elements are: 1 2 3 4 5 Example 2Test it NowOutput: Contents of a vector are: Java Android Python COBOL Elements of the array: Java Android Python COBOL Example 3Test it NowOutput: The elements are: 10 30 20 40 null Next TopicJava Vector |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India