Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners try to execute this code getting class cast exception, please resolve it.
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


pavans
try to execute this code getting class cast exception, please resolve it.
0 Answer(s)      2 years and 9 months ago
Posted in : Java Beginners


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;

}

}


Advertisement
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
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 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
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
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
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..., 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
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
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 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 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
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
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
Super class of an Exception class
Super class of an Exception class  hello,,, What is super class of an Exception class?   hii,, the super class of an exception is throwable class. and the super class of an throwable class is the object class
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
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
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  
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  Codeclass... is by using try catch block shown in following code sample:  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
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
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
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
Advertisements
 

 

 

DMCA.com