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

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









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 - Development process
class cast Exception  hi deepak this sampath,am facing the problem with printer connection with java application. Every time am getting the class cast exception and iam sending the code please check this and correct me
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
Getting Exception
Getting Exception  How to get exception from commented code in java
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   sir i am Getting following exception when... running it will throwing an exception please help me sir thanks.../apache/poi/poifs/filesystem/POIFSFileSystem I have used ur code import
Getting an exception - JSP-Servlet
exception please help me sir if an changes tel me sir thanks in advance...;Hi Friend, Try the following code: 1)excel.jsp: Enter XLS file name...Getting an exception  sir i changed to that ie InputStream myInput1
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
Super class of an Exception class
Super class of an Exception class  hello,,, What is super class of an Exception class?   hii,,ADS_TO_REPLACE_1 the super class of an exception is throwable class. and the super class of an throwable class
Getting an exception - JSP-Servlet
Getting an exception  thanks sir for u r reply ,but i already added that jar file sir even though i m getting an exception sir please help me sir ... thanks in advance..  Hi Friend, You can do one thing, replace
Getting an exception - JSP-Servlet
Getting an exception  Dear sir,while executing this code i am getting a following error ,i am sending my code also please help me sir... //following is a code int a = 0, b = 1, c = 2, d = 3, e = 4,f=0; //int a, b, c, d, e
Getting an exception - JSP-Servlet
Getting an exception  sir i m Getting an following exception while... sending message; nested exception is: java.io.FileNotFoundException... (); try{ Properties props = System.getProperties(); if (host != null
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 an exception - JSP-Servlet
Getting an exception  sir i used u r code for sending a mass email by reading an excel sheet,but i am getting a following error so please help me if any changes in code . thanks in advance.. java.io.IOException: Invalid
Getting an exception - JSP-Servlet
Getting an exception  sir i used u r code for sending a mass email by reading an excel sheet,but i am getting a following error so please help me if any changes in code . thanks in advance.. java.io.IOException: Invalid
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
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
I am getting this exception
I am getting this exception   Exception in thread "main" org.hibernate.exception.GenericJDBCException: Cannot open connection at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java
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
invalid class exception
invalid class exception  Wondering why invalid class exception occurs
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 exception in Assocation & Join. - Hibernate
Getting exception in Assocation & Join.  select product0_.id as id0...) exception setting property value with CGLIB (set hibernate.cglib.use_reflection... org.hibernate.PropertyAccessException: exception setting property value with CGLIB
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
class not found exception
class not found exception  org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilterprint("code sample
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
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
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
how to execute this code - JSP-Servlet
how to execute this code  hi guys can any help me in executing this bank application http://www.roseindia.net/jsp/bank.shtml, i need to use any database plz tell me step-to-step procedure for executing this,i need to create
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
Java exception class
Java exception class  What classes of exceptions may be caught by a catch clause
Exception Handling with and without using try catch block
to explicitly make try catch block then to you program write throws Exception to your method where Exception handling is required  Code:  ADS...(exceptionHandle.java:7)  Now the other way to use Exception Handling is by using try
Example to show cast exception in java
Example to show cast exception in java  ... a program that makes understand cast exception in java. The casting mean... cast exception in your programs. The example will show you to convert one data
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
Insert data in mysql database through jsp using Prepared Statement ---- Please Resolve it
Resolve it   I have tried the following code Database creation... this code on tomcat server i caught with following exception after clicking...!!!!! Please Resolve it , thanks in advance  Please visit the following
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
Insert data in mysql database through jsp using Prepared Statement ---- Please Resolve it
Insert data in mysql database through jsp using Prepared Statement ---- Please Resolve it   I have tried the following code Database creation... what was wrong!!!!! Please Resolve it , thanks in advance  
Please develop code - Development process
Please develop code  i want to develop a program that search a file... directory  Hi Friend, Following code searches the file. import java.io.*; import java.util.*; public class SearchFile { private static void
please provide the code
please provide the code   Develop a multi-client chat application
Please provide the code
Please provide the code   Write a program to recursively download the web pages available in the given site URL
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 provide the code
Please provide the code   Program to find depth of the file in a directory and list all files those are having more number of parent directories

Ads