❮ Previous Next ❯

Java StringTokenizer

It is the specially designed class for tokenization activity.
This class is present in java.util package.

import java.util.*;
class RegExDemo5
{
public static void main(String[] args)
{
StringTokenizer st=new StringTokenizer("Silan Software");
while(st.hasMoreTokens())
{
System.out.println(st.nextToken());
}
}
}
Output
Silan
Software

Note : The default regular expression of StringTokenizer is space.

StringTokenizer st=new StringTokenizer("02-08-1983","-");
while(st.hasMoreTokens())
{
System.out.println(st.nextToken());
}
The output will be:
02
08
1983

Write a regular expression to represent 10 digit mobile numbers:
Rules :

The regular expression is:
[7-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]
or
[7-9][0-9]{9}
or
[789][0-9]{9}
{9} represents 9 times

Suppose my requirement is mobile number can be 10 digits or 11 digits.
If it is 11 digits number then the first digit is 0. Then the regular expression is:
0?[7-9][0-9]{9}
0?: represents quantifier meaning is at most one time 0, followed by 10digits number.
Suppose my mobile number is 10 digits or 11 digits or 12 digits
If the number is 12 digits, then first two digits should be 91. The required regular expression is:
(0/9)?[7-9][0-9]{9}

❮ Previous Next ❯



  Tutorials

Popular Links

Contact Us

address Plot No-N6/530,2ND Floor
Nayapalli,Jayadev Vihar
      Bhubaneswar-751015
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved