Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8858303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:47:52+00:00 2026-06-14T14:47:52+00:00

i was looking for a way to automate all the casting needed to have

  • 0

i was looking for a way to “automate” all the casting needed to have List operations available for plain arrays. the issue is that

public static Object[] arrayRemoveAll(Object[] oA, Object[] removeA) {
    List<Object> l = new ArrayList<Object>(Arrays.asList(oA));
    l.removeAll(Arrays.asList(removeA));
    return l.toArray(new Object[l.size()]);
}

always gives me ClassCastException when i try to cast the object back into its original array type (e.g. if i call (String[])arrayRemoveAll(strA, strA2)).

i understand why this happens, but is there any neat way to circumvent this? i would love to be able to use a general function for some of the standard List operations.

thanks a lot in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:47:53+00:00Added an answer on June 14, 2026 at 2:47 pm

    How about

    public static <T> T[] arrayRemoveAll(T[] oA, Object[] removeA) {
        List<T> l = new ArrayList<T>(Arrays.asList(oA));
        l.removeAll(Arrays.asList(removeA));
        return l.toArray(Arrays.copyOf(oA, l.size()));
    }
    

    Personally, I’d avoid the cost overhead of all the conversions to list and manually write my loops, though. It does not get that much more verbose.

    Also, if you are already using Commons Lang, it has ArrayUtils#removeElements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for somewhere that has a list of all XML tags, with their
I'm looking for a way to automate the configuration of Android devices en masse.
I am looking for a way to automate the production of an offline product
I'm looking for way to create list view as like in IOS with pinned
My problem is that I was looking for way to use both storyboard and
I am looking for an automated way to iterate over all ObjectQueries and set
I'm looking for a way to automate the start-up of my development environment. I
I'm basically looking for a way to automate typing stuff like the following: cout
I'm looking into creating a automated way to check the running version of our
I'm looking a way to enable IP logging with log4net in ASP.NET. I found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.