|
||
|
|||
|
Not sure if this is in the right place but heres my problem.
I have a char 2D array. I want to convert the values in this array to an int array using some form of dictionary. for example A = 1 B = 2 C = 3 D = 4 input array : {A,C,D,A,C,B} output array:{1,3,4,1,3,2} can anyone advise me on how to do this Thanks Scottj996
|
|
|||
|
is this what you looking for?
Java Code
TreeMap tm = new TreeMap();
tm.put('A', 1);
tm.put('B', 2);
tm.put('C', 3);
tm.put('D', 4);
BufferedReader myBuff = new BufferedReader(new InputStreamReader(System.in));
char[] s1 = myBuff.readLine().toCharArray();
Vector v1 = new Vector();
for(int i = 0;i<s1.length;i++){
v1.add(tm.get(Character.toUpperCase(s1[i])));
}
System.out.println(v1.toString());
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [SOLVED] Help Converting to an Acronym | CheekySpoon | What's Wrong With My Code? | 2 | 02-02-2010 05:37 PM |
| Converting Hex to Decimal | r2ro_serolf | Java Theory & Questions | 8 | 10-11-2009 06:07 PM |
| Converting a method from ArrayList so it is capable with an Array | BlueJ1 | Collections and Generics | 2 | 08-07-2009 10:22 PM |
| converting to .exe | haygaurav | Java IDEs | 4 | 01-05-2009 08:32 PM |
| Converting Hexadecimal to Char | nathanernest | Java Theory & Questions | 2 | 08-04-2009 08:12 AM |