0

I have a method with a Parameter Country. This Parameter only Contains an abbreviation of the Country. In the method i want to print the full name of the Country without switch case or something, but with predefined Strings

final String VA="Vatikan";
String country="VA";
system.out.println(country);
//Is it possible that it Prints Vatikan now?
//I know not with that code but is there a possibillity to do that.
3
  • I try to explain, I have a method with a Parameter Country. This Parameter only Contains an abbreviation of the Country. In the method i want to print the full name of the Country without switch case or something, but with predefined Strings Commented Feb 15, 2013 at 0:45
  • You're looking for a Map. Commented Feb 15, 2013 at 0:47
  • @user1877211 Please update your question with the clarification! It's quite a different question with it. Commented Feb 15, 2013 at 0:47

3 Answers 3

6

No, but you could use a map to acheve the result you want. Specifically, to return the full name of the abbreviated country name:

String va="Vatikan";
String country="VA";
Map<String, String> abbreviationMap = new HashMap<String, String>();
abbreviationMap.put(country, va);
System.out.println(abbreviationMap.get(country)); //prints "Vatikan"
Sign up to request clarification or add additional context in comments.

Comments

1

This will assign it properly:

final String VA="Vatikan";
String country=VA;
System.out.println(country);

The String variable country will be pointed to whatever the variable VA is pointed to; because VA cannot change (it's final), country will point to "Vatikan".

Comments

0

What you are doing is that assigning a string "VA" to country, but you want to treat it as a variable, so remove the quotes("").

final String VA="Vatikan";
String country=VA;
System.out.println(country);

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.