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 8662231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:41:03+00:00 2026-06-12T16:41:03+00:00

Hi I have a strange question about java. I will leave out the background

  • 0

Hi I have a strange question about java. I will leave out the background info so as not to complicate it. If you have a variable named fname. And say you have a function returning a String that is “fname”. Is there a way to say reference the identifier fname via the String “fname”. The idea would be something like “fname”.toIdentifier() = value but obviously toIdentifier isn’t a real method.

I suppose a bit of background mite help. Basically I have a string “fname” mapped to another string “the value of fname”. And I want a way to quickly say the variable fname = the value of the key “fname” from the map. I’m getting the key value pair from iterating over a map of cookies in the form . And I don’t want to do “if key = “fname” set fname to “value of fname” because I have a ton of variables that need to be set that way. I’d rather do something like currentkey.toIdentifer = thevalue. Weird question maybe I’m overlooking a much easier way to approach this.

  • 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-12T16:41:04+00:00Added an answer on June 12, 2026 at 4:41 pm

    In a way you’re describing what reflection is used for:

    You refer to an object’s fields and methods by name.

    • Java Reflection

    However, most of the time when people ask a question like this, they’re better off solving their problem by re-working their design and taking advantage of data structures like Maps.


    Here’s some code that shows how to create a Map from two arrays:

    String[] keyArray = { "one", "two", "three" };
    String[] valArray = { "foo", "bar", "bazzz" };
    
    // create a new HashMap that maps Strings to Strings
    
    Map<String, String> exampleMap = new HashMap<String, String>();
    
    // create a map from the two arrays above
    
    for (int i = 0; i < keyArray.length; i++) {
        String theKey = keyArray[i];
        String theVal = valArray[i];
        exampleMap.put(theKey, theVal);
    }
    
    // print the contents of our new map
    
    for (String loopKey : exampleMap.keySet()) {
        String loopVal = exampleMap.get(loopKey);
        System.out.println(loopKey + ": " + loopVal);
    }
    

    Here’s a link to the JavaDoc for Map.

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

Sidebar

Related Questions

I have a question about strange return sizes when calling GetUserNameEx(). Maybe someone has
I have a strange question about session management. I implemented a form chain and
I have a strange question about Linq. I have this query: var results =
This might seem like a strange question, and perhaps I am not thinking about
I have a very basic question about MVC web applications in Java. Since the
I have a potentially strange question about this and jQuery plugins As I understand
I have probem / strange question, i got algorithm with few for loops and
I have a strange question concerning subroutines: As I'm creating a minimal language and
So I have a strange question. I have written a script that re-formats data
I know it is a strange question did someone have had a case where

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.