1

I want to print April as APR IN JAVA WHERE 4 comes as parameter to indicate April. what can i do?i tried the format 'MMM' but it prints 'Apr' in stead of 'APR'.

4 Answers 4

4

Use the String.toUpperCase() method.

Sign up to request clarification or add additional context in comments.

Comments

4

why not just upper case your 'MMM' result ?

Comments

1

With the SimpleDateFormat class you cannot or use String.toUpperCase() (as said Ben J) in conjunction with the "MMM".

This makes sense if you work with dates but if you just work with numbers (ie: 4) you can build a complete switch statement on the number...

2 Comments

I would recommend against the switch statement solution unless you are absolutely, positively, 100% certain that you will never ever have to cope with other languages in your app. And even then recommend against the switch solution. String.toUpperCase() is the right way to go.
Agree with you... The switch solution is a dirty solution but it's working ;)
1

Use String.subString and then apply String.toUpperCase to get desired result.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.