Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

Array Casting in java

Thu Oct 23, 2008 1:40 am

Can you guys help me on how to change an integer type of array into a
char type array is there a simple code of type casting array?



Re: Array Casting in java

Thu Oct 23, 2008 1:41 am

You'll have to do a loop and cast each element as you move it.
An example method to do this:
Code:
public char [] toCharArray (int [] intArray) {
char [] charArray = new char [intArray.length];
for (int i = 0; i < intArray.length; i++) {
charArray [i] = (char)intArray [i];
}
return charArray;
}


Using Java 5 and above, you can parameterize this code:

Post a reply
  Related Posts  to : Array Casting in java
 Casting Variables in php     -  
 casting to char + end of file     -  
 Java Two Dimensional Array     -  
 Adding vertical array in java     -  
 Need Help with Java Array Sorting Logic     -  
 quicksort algorithm implementation java code- array sorting     -  
 Bubble Sort Algorithm Java Implementation Code-Sorting Array     -  
 Array difference for associate array     -  
 Sort strings java-Sorting Array of Strings     -  
 compare an array with another array?     -  

Topic Tags

Java Arrays