每个字符的StringTokenizer定界符

每个字符的StringTokenizer定界符

问题描述:

我有一个应该在课程中使用StringTokenizer的字符串。我已经制定了实施该项目的计划,但是找不到如何将每个字符都用作分隔符的参考。

I've got a string that I'm supposed to use StringTokenizer on for a course. I've got my plan on how to implement the project, but I cannot find any reference as to how I will make the delimiter each character.

基本上,像河马校区是聚会场所这样的字符串,我需要将每个字符划分为令牌,然后将它们与一组值进行比较,然后换出一个特定的彼此。我知道如何做其他事情,但是分隔每个字符的分隔符是什么?

Basically, a String such as "Hippo Campus is a party place" I need to divide into tokens for each character and then compare them to a set of values and swap out a particular one with another. I know how to do everything else, but what the delimiter would be for separating each character?

如果您真的想使用您可以像下面这样使用StringTokenizer

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," ");

或者甚至可以为此使用split。

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);
}