Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Converting an array

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Thanked 0 Times in 0 Posts

    Default Converting an array

    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


  2. #2
    Junior Member
    Join Date
    Mar 2010
    Thanked 0 Times in 0 Posts

    Default Re: Converting an array

    is this what you looking for?

            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++){

    ps : don't forget to add the imports

Similar Threads

  1. Converting Hex to Decimal
    By r2ro_serolf in forum Java Theory & Questions
    Replies: 10
    Last Post: September 4th, 2011, 04:29 PM
  2. [SOLVED] Help Converting to an Acronym
    By CheekySpoon in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 2nd, 2010, 01:37 PM
  3. Converting a method from ArrayList so it is capable with an Array
    By BlueJ1 in forum Collections and Generics
    Replies: 2
    Last Post: July 8th, 2009, 05:22 PM
  4. Replies: 4
    Last Post: May 1st, 2009, 03:32 PM
  5. Program to convert Hexadecimal to its Character equivalent
    By nathanernest in forum Java Theory & Questions
    Replies: 2
    Last Post: April 8th, 2009, 03:12 AM