try to execute this code getting class cast exception, please resolve it.

Ads
 

try to execute this code getting class cast exception, please resolve it.

package test;

import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set;

public class Over { static int k[] = new int[5];

public static void main(String... ab) {
    int aa[] = new int[] { 2, 1, 2, 3 };
    int b[] = Over.removeDuplicates(aa);
    for (int ac = 0; ac < b.length; ac++) {
        System.out.println(b[ac]);
    }
}

public static int[] removeDuplicates(int[] a) {

    /*
     Please implement this method to
     remove all duplicates from the original array. Retain the order of the elements and
     always retain the first occurrence of the duplicate elements.
     For example, parameter: {2,1,2,3}, result: {2,1,3}
     */

    List list = Arrays.asList(a);
    System.out.println(list);
    Set<Integer> set = new HashSet<Integer>(list);
    Object obj[] = set.toArray();
    Integer o[] = new Integer[obj.length];
    for (int i = 0; i < obj.length; i++) {
        o[i] = (Integer) obj[i];
    }
    for (int i = 0; i < o.length; i++) {
        k[i] = o[i].intValue();
    }
    return k;

}

}

View Answers

Ads









Related Tutorials/Questions & Answers:
try to execute this code getting class cast exception, please resolve it.
try to execute this code getting class cast exception, please resolve it. ... java.util.List; import java.util.Set; public class Over { static int k... int[] removeDuplicates(int[] a) { /* Please implement this method
Getting Exception on UseDefinedException sample program - Please help me how to resolve
Getting Exception on UseDefinedException sample program - Please help me how to resolve  class UseDefinedException extends Exception{ String msg...); } } } Hi, I tried above code but getting Exception : MyException cannot
Advertisements
Class Cast Exception Example in java
Class Cast Exception Example in java We are going to describe class cast exception in java. The class cast exception is a converting one data type into another data type. A Class cast exception is a thrown by java. In this example
Class Cast & illegal state Exception in blackberry
Class Cast & illegal state Exception in blackberry  tell me please i m facing class cast exception. when i click on Maps & iGoogle in Google Homepage on my emulator then it gives class cast & Illegal State exception
How do I resolve this Java Class not found exception?
How do I resolve this Java Class not found exception?  Hi, Many time new developer faces the Class not found exception. Why it happens and how to resolve this? Thanks   Hi, The main reason of this exception is un
Try and catch in Exception Handling.
Try and catch in Exception Handling.  How can we use try and catch...; try{ x=a/b; }catch (Exception er.... Then to perform exception handling, we have used try and catch block where we have
what are the jar files should i add to resolve the Exception(Class org.apache.jsp.index_jsp Not Found) ?
what are the jar files should i add to resolve the Exception(Class... to resolve the following Exception HTTP Status 500 - type Exception report... it from fulfilling this request. exception javax.servlet.ServletException: Wrapper
Getting an exception - JSP-Servlet
Getting an exception  Dear Sir , While sending a mail am getting an following exception javax.mail.MessagingException: 554 mail server permanently rejected message (#5. 3.0)so how to over come from this please help
Getting exception in hello world
Getting exception in hello world  I run your hibernate5 "hello world" program. But, getting an exception: ERROR: Table 'mydb.employee' doesn't exist Exception in thread "main" javax.persistence.PersistenceException
Getting exception in hello world
Getting exception in hello world  I run your hibernate5 "hello world" program. But, getting an exception: ERROR: Table 'mydb.employee' doesn't exist Exception in thread "main" javax.persistence.PersistenceException
getting classnotfound exception while running login application
getting classnotfound exception while running login application  hi, I am getting Error creating bean with name 'urlMapping' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Cannot resolve reference
MYSQL EXCEPTION -DATA TRUNCATION..pls resolve it
MYSQL EXCEPTION -DATA TRUNCATION..pls resolve it  while running my...;<td class="s2">ZIP Code:</td> <td class="s3"><input...; <tr align="center"> <div class="ab"> <td> <a href="E
invalid class exception
invalid class exception  Wondering why invalid class exception occurs
MYSQL EXCEPTION -DATA TRUNCATION..pls resolve it
MYSQL EXCEPTION -DATA TRUNCATION..pls resolve it  while running my...; <tr align="center"> <div class="ab"> <td> <a href="E:\JE...; <tr></tr> <tr></tr> </table> <h1 class="s1
class not found exception
class not found exception  org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilterprint("code sample
getting db in action class
getting db in action class  hi, Am usin struts in ma application... n i need to interact with the db .. so i used.. getDataSource(request) but it gives me an error.. java.lang.NoSuchMethodError: LoginAction.getDataSource(Ljavax
my hibernate showing the following exception so how i can resolve it
my hibernate showing the following exception so how i can resolve it   Caused by: java.lang.ClassNotFoundException: org.hibernate.Session...) at java.lang.ClassLoader.loadClass(Unknown Source) Could not find the main class
Getting Null pointer Exception in the jsp page
Getting Null pointer Exception in the jsp page  I have developed this jsp page to store the data in database.While storing the value of check box in database I am getting null pointer exception in the following code
Getting Null pointer Exception in the jsp page
Getting Null pointer Exception in the jsp page  I have developed this jsp page to store the data in database.While storing the value of check box in database I am getting null pointer exception in the following code
Getting Null pointer Exception in the jsp page
Getting Null pointer Exception in the jsp page  I have developed this jsp page to store the data in database.While storing the value of check box in database I am getting null pointer exception in the following code
Getting Null pointer Exception in the jsp page
Getting Null pointer Exception in the jsp page  I have developed this jsp page to store the data in database.While storing the value of check box in database I am getting null pointer exception in the following code
CLASS NOT FOUND EXCEPTION
CLASS NOT FOUND EXCEPTION   I AM USING INTERNET EXPLORER VERSION 6.00... LOGIN IN SITE AND UPDATE DIGITAL CERTIFICATE THE ERROR SHAWN IS BELOW CLASS NOT FOUND EXCEPTION AND THE BOX IS DISPLAYED AND I CLICK ON DETAILS BUTTON
different output trying to execute same java code
different output trying to execute same java code  i am using net... javax.comm.*; public class SimpleRead implements Runnable, SerialPortEventListener... = new SimpleRead(); } } } } public SimpleRead() { try
different output trying to execute same java code
different output trying to execute same java code  i am using net... javax.comm.*; public class SimpleRead implements Runnable, SerialPortEventListener... = new SimpleRead(); } } } } public SimpleRead() { try
different output trying to execute same java code
there is different output trying to execute same java code...different output trying to execute same java code  i am using net... javax.comm.*; public class SimpleRead implements Runnable, SerialPortEventListener
Error:No Class Found Exception:org.postgresql.driver
Error:No Class Found Exception:org.postgresql.driver  Error:No Class Found Exception:org.postgresql.driver while connecting JDBC With PostgreSQL 8.4 I m running My Program with java 6.0
AwizardController class code
AwizardController class code  Hi deepak, Thank you for responding me for this answer.I want AwzardController class code, can you please post
Please help with this code
Please help with this code  I need some help getting the Search method below to work with the menu, and I also cannot figure out how to get my bubble... at this point! :( import java.util.*; public class StudentProcessor2
could anyone please help with the code.
could anyone please help with the code.  protected void doPost...(request, response); } } could anyone please check the code. If i enter... the details to the bean class */ userLogin_bean obj=new userLogin_bean
please provide the code
please provide the code   Develop a multi-client chat application
ModuleNotFoundError: No module named 'sphinx_execute_code'
ModuleNotFoundError: No module named 'sphinx_execute_code'  Hi, My... named 'sphinx_execute_code' How to remove the ModuleNotFoundError: No module named 'sphinx_execute_code' error? Thanks   Hi

Ads