Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to convert integer array to character array

 
ragz wifer
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello

I declared an integer array with some values in it and i want to display array values in console using System.out.write() method

i could not trace out can someone help me


thanks in advance
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably want something like this:

 
vinayak jog
Ranch Hand
Posts: 83
MySQL Database Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use multidimensional character array becoz casting in the reverse direction is not possible
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vinayak jog wrote:Use multidimensional character array becoz casting in the reverse direction is not possible

First please UseRealWords. Second: I don't see how to implement that nor do I see how it would help. Could you explain it?
 
Campbell Ritchie
Sheriff
Posts: 48910
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try... but I hardly think that is a brilliant piece of coding. Also that method declares a checked Exception (IOException) which needs to be dealt with.
 
ragz wifer
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

i am new to java

i have declared an integer array like



Its showing output in some other characters i can say as boxes like


one more thing is it is possible to achieve using println statement but i want to do this using write method

Is there a way to figure it ? i found that if the array was character array output is fine
but initially i wish to give integer input

can i know how to do this
 
Campbell Ritchie
Sheriff
Posts: 48910
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A trip to the Unicode site might help. Remember 1 and 2 are non-printing characters; you will find them in the .pdf from that link. try starting at 0x20 and going up to 0x30 in your array.
 
Rob Spoor
Sheriff
Pie
Posts: 20526
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out.write(i) will treat the int as a byte, ignoring everything but the last 8 bits. So if i is 32 this will not write 32 but a space instead.
 
Campbell Ritchie
Sheriff
Posts: 48910
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . but you will still see the other characters from 0x21 to 0x30 . . . You will get  !"#$%&'()*+,-./0, maybe split over 17 lines if you are using \n.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic