CompositeName get() method in Java with ExamplesThe javax.naming.CompositeName is a class containing a get() as a method. To obtain a component of this composite name object, utilize the CompositeName class. The component present at that place is obtained from the composite name object using the position that was supplied as a parameter. Syntax: Parameters: The 0-based index of the component to be retrieved, posn, is accepted by this method. It needs to be between 0 and size(). Return value: The element at index posn is returned by this method. Exception: If posn is outside the given range, this function throws an ArrayIndexOutOfBounacdsException exception. Example 1:The Java program that is given shows how to manage and get the components of a composite name using the CompositeName class from the javax.naming package. A CompositeName object is initialized by the application with the composite name string "pq/yaz/abz/xe/klm," which is a series of components divided by slashes. Then, at index locations 1 and 4, it retrieves and prints particular components from the composite name using the get() method; these components are "yaz" and "klm," respectively. Implementation: FileName: CompositenameExample1.java Output: The component at the index position is: yaz The component at the index position is: klm Example 2:The given Java program shows how to handle a composite name formed up of several parts by using the CompositeName class from the javax.naming package. A CompositeName object is initialized by the application with the string "aaa/srty/dtfd/f/366/v154+j/enh/d," which is a series of components divided by slashes. The components "v154+j" and "366," which are found at index locations 5 and 4, are the result of using the get() function to extract particular components from this composite name. Implementation: FileName: CompositenameExample2.java Output: The component at the index position is: v154+j The component at the index position is: 366 |
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