Usando tokens

1 resposta
maxmustang

fala galera, blz?
meu problema é o seguinte
o meu cliente escreve um texto utilizando tokens…
mais ou menos assim

me deram a idéia de usar o StringTokenizer, pra poder separar as palavras e etc
tem algum outro jeito? ou um jeito melhor?

1 Resposta

Eric_Yuzo

StringTokenizer é legado. O próprio javadoc diz isso. Prefira usar split da classe String.

javadoc:
StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead.

The following example illustrates how the String.split method can be used to break up a string into its basic tokens:

String[] result = "this is a test".split("\\s");
     for (int x=0; x<result.length; x++)
         System.out.println(result[x]);

prints the following output:

this
     is
     a
     test</blockquote>
Criado 6 de janeiro de 2011
Ultima resposta 6 de jan. de 2011
Respostas 1
Participantes 2