aspose file tools*
The moose likes Beginning Java and the fly likes How to convert integer array to character array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to convert integer array to character array" Watch "How to convert integer array to character array" New topic
Author

How to convert integer array to character array

ragz wifer
Greenhorn

Joined: Dec 22, 2010
Posts: 22
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

Joined: Oct 25, 2008
Posts: 2700

You probably want something like this:



"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
vinayak jog
Ranch Hand

Joined: Apr 01, 2011
Posts: 81

Use multidimensional character array becoz casting in the reverse direction is not possible
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

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

Joined: Oct 13, 2005
Posts: 39834
    
  28
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

Joined: Dec 22, 2010
Posts: 22
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

Joined: Oct 13, 2005
Posts: 39834
    
  28
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

Joined: Oct 27, 2005
Posts: 19761
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39834
    
  28
. . . 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.
 
 
subject: How to convert integer array to character array