Trying to convert a char array to integer array in Java with this code

前端 未结 3 1830
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-26 21:13

I\'m trying to convert an array of characters into integers, so I can get the ascii code, but the code I have doesn\'t seem to be working.

import javax.swing.*;
         


        
3条回答
  •  迷失自我
    2021-01-26 22:03

    Try it this way...

    char[] charArray = phrase.toCharArray();
    
    int[] intArray = new int[charArray.length];
    
    int i=0;
    
    for (char c : charArray){
    
          intArray[i] = c;
          i++;
    
    }
    

提交回复
热议问题