Вопрос по string, arrays, java, character – Преобразование строки в массив символов в Java

96

Error: User Rate Limit ExceededStringError: User Rate Limit ExceededсимволError: User Rate Limit ExceededtoCharArray()Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded barsju
Error: User Rate Limit Exceeded blackcompe
Error: User Rate Limit ExceededcharError: User Rate Limit ExceededCharacterError: User Rate Limit ExceededCharacter.valueOf(mychar)Error: User Rate Limit Exceeded ee.
Error: User Rate Limit Exceeded Eric Hartford

Ваш Ответ

12   ответов
49

:

String str = "testString";

//[t, e, s, t, S, t, r, i, n, g]
Character[] charObjectArray = 
    str.chars().mapToObj(c -> (char)c).toArray(Character[]::new); 

get an IntStream of the characters (you may want to also look at codePoints()) map each 'character' value to Character (you need to cast to actually say that its really a char, and then Java will box it automatically to Character) get the resulting array by calling toArray()
2

String#toCharArrayError: User Rate Limit ExceededcharError: User Rate Limit ExceededCharacterError: User Rate Limit ExceededcharError: User Rate Limit ExceededCharacterError: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceededchar[]).

32

public Character[] toCharacterArray( String s ) {

   if ( s == null ) {
     return null;
   }

   int len = s.length();
   Character[] array = new Character[len];
   for (int i = 0; i < len ; i++) {
      array[i] = new Character(s.charAt(i));
   }

   return array;
}
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
2

/**
 * @param sourceString
 *            :String as argument
 * @return CharcterArray
 */
public static Character[] toCharacterArray(String sourceString) {
    char[] charArrays = new char[sourceString.length()];
    charArrays = sourceString.toCharArray();
    Character[] characterArray = new Character[charArrays.length];
    for (int i = 0; i < charArrays.length; i++) {
        characterArray[i] = charArrays[i];
    }
    return characterArray;
}
0

public static Character[] convertStringToCharacterArray(String str) {
    if (str == null || str.isEmpty()) {
        return null;
    }
    char[] c = str.toCharArray();
    final int len = c.length;
    int counter = 0;
    final Character[] result = new Character[len];
    while (len > counter) {
        for (char ch : c) {
            result[counter++] = ch;
        }
    }
    return result;
}
0

String str = "somethingPutHere";
Character[] c = ArrayUtils.toObject(str.toCharArray());
chaining is always bestError: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
164

String str = "testString";
char[] charArray = str.toCharArray();
Character[] charObjectArray = ArrayUtils.toObject(charArray);
Error: User Rate Limit Exceeded
ArrayUtilsError: User Rate Limit Exceededcommons-langError: User Rate Limit Exceeded
1

String str="I am a good boy";
    char[] chars=str.toCharArray();

    Character[] characters=new Character[chars.length];
    for (int i = 0; i < chars.length; i++) {
        characters[i]=chars[i];
        System.out.println(chars[i]);
    }
0

StringReaderjava.ioread(char[] cbuf)

String str = "hello";
char[] array = new char[str.length()];
StringReader read = new StringReader(str);

try {
    read.read(array); //Reads string into the array. Throws IOException
} catch (IOException e) {
    e.printStackTrace();
}

for (int i = 0; i < str.length(); i++) {
        System.out.println("array["+i+"] = "+array[i]);
}

array[0] = h
array[1] = e
array[2] = l
array[3] = l
array[4] = o
4

String s="Welcome to Java Programming";
char arr[]=s.toCharArray();
for(int i=0;i<arr.length;i++){
    System.out.println("Data at ["+i+"]="+arr[i]);
}

Data at [0]=W
Data at [1]=e
Data at [2]=l
Data at [3]=c
Data at [4]=o
Data at [5]=m
Data at [6]=e
Data at [7]= 
Data at [8]=t
Data at [9]=o
Data at [10]= 
Data at [11]=J
Data at [12]=a
Data at [13]=v
Data at [14]=a
Data at [15]= 
Data at [16]=P
Data at [17]=r
Data at [18]=o
Data at [19]=g
Data at [20]=r
Data at [21]=a
Data at [22]=m
Data at [23]=m
Data at [24]=i
Data at [25]=n
Data at [26]=g
Error: User Rate Limit Exceeded
0

public JTextField display;
String number=e.getActionCommand();

display.setText(display.getText()+number);

ch=number.toCharArray();
for( int i=0; i<ch.length; i++)
    System.out.println("in array a1= "+ch[i]);
2

charAt(i)Character[]arrayname[i] = string.charAt[i].

Похожие вопросы