StringTokenizer delimiters for each Character

泄露秘密 提交于 2019-12-02 08:06:10

If you really want to use StringTokenizer you could use like below

     String myStr = "Hippo Campus is a party place".replaceAll("", " ");
    StringTokenizer tokens = new StringTokenizer(myStr," ");

Or even you can use split for this. And your result will be String array with each character.

String myStr = "Hippo Campus is a party place";
String [] chars = myStr.split("");

for(String str:chars ){
  System.out.println(str);
}

Convert the String to an array. There is no delimiter for separating every single character, and it wouldnt make sense to use string tokenizer to do that even if there was.

You can do something like:

 char[] individualChars = someString.toCharArray;

Then iterate through that array like so:

for (char c : individualChars){
    //do something with the chars.
}

You can do some thing like make the string in to a Char array.

char[] simpleArray = sampleString.toCharArray();

This will split the String to a set of characters. So you can do the operations which you have stated above.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!