Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

casting char[] to int in java

  • 29-10-2008 09:39PM
    #1
    Closed Accounts Posts: 34


    say I have some stuff in a char array data[] and data = 7. I want to add data to an int or change data into an int so I can add it, but I keep getting the ASCII table value 55.

    I've tried int x = (int)data but that didn't work. This is bugging me now because I'm sure its something simple I've just become confused looking at all the int to char tutorials but can't seem to find a char[] to int one. Anyone got any ideas or pointers ?


Comments

  • Closed Accounts Posts: 34 jackofnotrades


    Got it ... had to make it into a string first, If anyone has an easier way I wouldn't mind seeing it !

    String strChar2Int = String.valueOf(data);
    x = Integer.parseInt(strChar2Int);


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    Don't know if this works but have you tried
    stringByte = String.valueOf(data[i]);
    int x    = Integer.parseInt(stringByte);
    

    Edit: Ok you just got there before me!


Advertisement