0

The array example:

String wordList[] = {"pig", "dog", "cat", "fish", "bird"}

I have transform Str to Char , Half Width to Full Width and UpperCase. look like

for(int i = 0 ; i < str.length(); i++){
char cha = str.charAt(i);
cha = Character.toUpperCase(cha);
cha += 65248;
System.out.print(cha);
}

So, I have a question about how to make a new array such as {'p', 'i', 'g'};

2
  • 2
    docs.oracle.com/javase/7/docs/api/java/lang/… Commented Nov 27, 2017 at 11:29
  • Have a look at the toCharArray() method. That does what you need. You can use that with an enhanced for loop to iterate over your string. Commented Nov 27, 2017 at 11:41

2 Answers 2

1

Maybe this can be usefull

for (String str : wordList){
   char[] charArray = str.toCharArray();
   System.out.println(charArray.toString());
}
Sign up to request clarification or add additional context in comments.

Comments

0

The following will print [PIG, DOG, CAT, FISH, BIRD]

String[] words = new String[]{"pig", "dog", "cat", "fish", "bird"};
char[][] charWords = new char[words.length][];

for (int j = 0; j < words.length; j++) {
    String str = words[j];
    char[] chars = new char[str.length()];

    for (int i = 0; i < str.length(); i++) {
        char cha = str.charAt(i);
        cha = Character.toUpperCase(cha);
        cha += 65248;
        chars[i] = cha;
    }

    charWords[j] = chars;
}

System.out.println(Arrays.stream(charWords).map(String::new).collect(Collectors.toList()));

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.