1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
/* Java StringTokenizer - Specify Delimiter example. This example shows how a specify a delimiter for StringTokenizer object. The default delimiters are t character (tab), n character (new line), r character (carriage return) and f character (form feed). */ import java.util.StringTokenizer; public class StringTokenizerSpecifyDelimiterExample { public static void main(String[] args) { /* * There are two ways to specify a delimiter for a StringTokenizer object. * 1. At the creating time by specifying in the StringTokenizer constructor * 2. Specify it in nextToken() method */ //1. Using StringTokenizer constructor StringTokenizer st1 = new StringTokenizer("Java|StringTokenizer|Example 1", "|"); //iterate through tokens while(st1.hasMoreTokens()) System.out.println(st1.nextToken()); //2. Using nextToken() method. Note that the new delimiter set remains the //default after this method call StringTokenizer st2 = new StringTokenizer("Java|StringTokenizer|Example 2"); //iterate through tokens while(st2.hasMoreTokens()) System.out.println(st2.nextToken("|")); } } /* Java StringTokenizer Example 1 Java StringTokenizer Example 2 */ |
Is there a way to specify a bunch of delimiters without actually typing them one by one…
For bunch of delimt you specify them continuously.
Eg – “?!;:'”/*@#’\’ “