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

  • Home
  • SEARCH
  • 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 8334679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:25:59+00:00 2026-06-09T03:25:59+00:00

why does this run: static TreeMap<String, int[]> configs = new TreeMap<String, int[]>(); int[] upperarms_body

  • 0

why does this run:

    static TreeMap<String, int[]> configs = new TreeMap<String, int[]>();

    int[] upperarms_body = {2,3,4,6};
    int[] left_arm = {1,2};
    int[] right_arm = {6,7};
    int[] right_side = {5,6,7};
    int[] head_sternum = {3,4};


    configs.put("upperarms_body", upperarms_body);
    configs.put("left_arm", left_arm);
    configs.put("right_arm", right_arm);
    configs.put("right_side", right_side);
    configs.put("head_sternum", head_sternum);



    // create a config counter
    String[] combi = new String[configs.keySet().size()];

    Set<String> s = configs.keySet();
    int g = 0;
    for(Object str : s){
        combi[g] = (String) str; 
    }

and this not:

  static TreeMap<String, int[]> configs = new TreeMap<String, int[]>();

    int[] upperarms_body = {2,3,4,6};
    int[] left_arm = {1,2};
    int[] right_arm = {6,7};
    int[] right_side = {5,6,7};
    int[] head_sternum = {3,4};

    configs.put("upperarms_body", upperarms_body);
    configs.put("left_arm", left_arm);
    configs.put("right_arm", right_arm);
    configs.put("right_side", right_side);
    configs.put("head_sternum", head_sternum);



    //get an array of thekeys which are strings
    String[] combi = (String[]) configs.keySet().toArray();
  • 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-09T03:26:01+00:00Added an answer on June 9, 2026 at 3:26 am

    The method toArray() returns an Object[] instance, which cannot be cast to String[], just like an Object instance cannot be cast to String:

    // Doesn't work:
    String[] strings = (String[]) new Object[0];
    
    // Doesn't work either:
    String string = (String) new Object();
    

    However, because you can assign String to Object, you can also put String into Object[] (which is what probably confuses you):

    // This works:
    Object[] array = new Object[1];
    array[0] = "abc";
    
    // ... just like this works, too:
    Object o = "abc";
    

    The inverse wouldn’t work, of course

    String[] array = new String[1];
    // Doesn't work:
    array[0] = new Object();
    

    When you do this (from your code):

    Set<String> s = configs.keySet();
    int g = 0;
    for(Object str : s) {
        combi[g] = (String) str; 
    }
    

    You’re not actually casting an Object instance to String, you’re casting a String instance declared as an Object type to String.

    The solution to your problem would be any of these:

    String[] combi = configs.keySet().toArray(new String[0]);
    String[] combi = configs.keySet().toArray(new String[configs.size()]);
    

    Refer to the Javadoc for more info about Collection.toArray(T[] a)

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

Sidebar

Related Questions

Does this code cause a memory leak: int main(){ int * a = new
I have an application (winform exe) that I run several times. Does this mean
I only want this function to run if .toolbar li does not have the
Can anyone tell me why does this timer run only once? import java.awt.*; import
Why does this happen? Please observe the following code: static class StringExtension { public
I have the following code, does this run an endless loop? I am trying
Does this code always evaluate to false? Both variables are two's complement signed ints.
Does this function has the same behavior that memset ? inline void SetZeroArray( void
Does this work well as a Singleton in actionscript? i.e. are there any gotchas
Does this mean I can't update another table from a trigger if I'm using

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.