Hi I recently started a new job and i've just been giving my first proper coding task. It is to write a method that will take a value and convert it to something else. eg. If the method receives Payment it will return 'P'. I'm just looking for the best way I can do this, I was thinking of just using an if or switch statement but if anyone has any better ideas let me know. I want to prove to my team that I am a good coder.


Recommended Answers

All 3 Replies

Is there a pre-defined set of inputs and corresponding outputs? If so a Map would be the obvious choice.

Yea there is, i never thought of using a map..I was thinking having to use an if or a switch would be a lot of line of code. Thank you!

Depending on how fixed the set of values is, you can easily hold the mappings in an external file and read them into a Map at startup, which could be a better option for maintenace purposes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.