Example usage for java.util StringTokenizer StringTokenizer

List of usage examples for java.util StringTokenizer StringTokenizer

Introduction

In this page you can find the example usage for java.util StringTokenizer StringTokenizer.

Prototype

public StringTokenizer(String str, String delim) 

Source Link

Document

Constructs a string tokenizer for the specified string.

Usage

From source file:Main.java

public static void main(String[] args) {

    StringTokenizer st = new StringTokenizer("tutorial/from/java2s.com", "/");

    // checking next token
    System.out.println("Next token is : " + st.nextToken("/"));
    System.out.println("Next token is : " + st.nextToken("/"));
    System.out.println("Next token is : " + st.nextToken("/"));
}

From source file:Main.java

public static void main(String[] args) {
    int i = 0;//from  ww w.j  av  a 2s.c om
    String str = "one);two);three);four";
    StringTokenizer st = new StringTokenizer(str, ");");
    String temp[] = new String[st.countTokens()];

    while (st.hasMoreTokens()) {
        temp[i] = st.nextToken();
        System.out.println(temp[i]);
        i++;
    }
}

From source file:MainClass.java

public static void main(String args[]) {
    String in = "a=1;" + "b=2";

    StringTokenizer st = new StringTokenizer(in, "=;");
    while (st.hasMoreTokens()) {
        String key = st.nextToken();
        String val = st.nextToken();
        System.out.println(key + "\t" + val);
    }/*from  w  w  w  .  j  a  va 2 s  .  c om*/
}

From source file:Main.java

public static void main(String[] args) {
    String temp = "<NOUN>Nitin<NOUN> <NOUN>test<NOUN>";
    String finalString = "this is a test";

    StringTokenizer x = new StringTokenizer(temp, " ");
    while (x.hasMoreTokens()) {

        String token = x.nextToken();

        String findword = token.replaceAll("<NOUN>", "");
        String findword1 = findword.replaceAll("</NOUN>", "");

        String modifiedString = finalString.replaceFirst(findword1, "<NOUN>" + findword1 + "</NOUN>");
        finalString = modifiedString;/*from   w w w  .  jav  a  2s  .  c  o  m*/
    }
    System.out.println(finalString);
}

From source file:Main.java

public static void main(String[] args) {
    String str = "This is a  test, this is another test.";
    String delimiters = "  ,"; // a space and a comma
    StringTokenizer st = new StringTokenizer(str, delimiters);

    System.out.println("Tokens  using a  StringTokenizer:");
    String token = null;/*from w  w  w  . j  a  v a2  s . co m*/
    while (st.hasMoreTokens()) {
        token = st.nextToken();
        System.out.println(token);
    }
}

From source file:Finger.java

public static void main(String[] arguments) throws Exception {
    StringTokenizer split = new StringTokenizer(arguments[0], "@");
    String user = split.nextToken();
    String host = split.nextToken();

    Socket digit = new Socket(host, 79);
    digit.setSoTimeout(20000);/* www . j ava2 s.  c  o  m*/
    PrintStream out = new PrintStream(digit.getOutputStream());
    out.print(user + "\015\012");
    BufferedReader in = new BufferedReader(new InputStreamReader(digit.getInputStream()));
    boolean eof = false;
    while (!eof) {
        String line = in.readLine();
        if (line != null)
            System.out.println(line);
        else
            eof = true;
    }
    digit.close();
}

From source file:SubSupScriptPDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {//  w w w .  ja  v a2  s  . c  om
        PdfWriter.getInstance(document, new FileOutputStream("SubSupScriptPDF.pdf"));
        document.open();
        String s = "Text Text Text Text Text Text Text Text Text Text Text Text Text Text ";
        StringTokenizer st = new StringTokenizer(s, " ");
        float textrise = 6.0f;
        Chunk c;
        while (st.hasMoreTokens()) {
            c = new Chunk(st.nextToken());
            c.setTextRise(textrise);
            c.setUnderline(new Color(0xC0, 0xC0, 0xC0), 0.2f, 0.0f, 0.0f, 0.0f, PdfContentByte.LINE_CAP_BUTT);
            document.add(c);
            textrise -= 2.0f;
        }
    } catch (Exception ioe) {
        System.err.println(ioe.getMessage());
    }
    document.close();
}

From source file:MainClass.java

public static void main(String args[]) {
    // void copyToClipboard() {
    String toClipboard = "Hello from Java!";
    StringSelection ss = new StringSelection(toClipboard);
    Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
    clip.setContents(ss, ss);//from   w  w  w . j  a  va2  s . c om
    // Paste
    clip = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable contents = clip.getContents(new MainClass().getClass());
    if (contents == null)
        System.out.println("The clipboard is empty.");
    else {
        if (contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            try {
                String data = (String) contents.getTransferData(DataFlavor.stringFlavor);
                if (data == null)
                    System.out.println("null");
                else {
                    StringTokenizer st = new StringTokenizer(data, "\n");
                    while (st.hasMoreElements())
                        System.out.println(st.nextToken());
                }
            } catch (IOException ex) {
                System.out.println("IOException");
            } catch (UnsupportedFlavorException ex) {
                System.out.println("UnsupportedFlavorException");
            }
        } else
            System.out.println("Wrong flavor.");
    }

}

From source file:org.tdmx.server.runtime.ServerLauncher.java

public static void main(String[] args) {
    String javaVersion = System.getProperty("java.version");

    StringTokenizer tokens = new StringTokenizer(javaVersion, ".-_");

    int majorVersion = Integer.parseInt(tokens.nextToken());
    int minorVersion = Integer.parseInt(tokens.nextToken());

    if (majorVersion < 2 && minorVersion < 7) {
        log.error("TDMX-Server requires Java 7 or later.");
        log.error("Your java version is " + javaVersion);
        log.error("Java Home:  " + System.getProperty("java.home"));
        System.exit(-1);// w  w w . j a  v  a 2 s .  c o m
    }

    // Construct the SpringApplication
    BeanFactoryLocator beanFactoryLocator = ContextSingletonBeanFactoryLocator.getInstance();
    BeanFactoryReference beanFactoryReference = beanFactoryLocator.useBeanFactory("applicationContext");
    ApplicationContext context = (ApplicationContext) beanFactoryReference.getFactory();

    SslServerSocketInfo si = (SslServerSocketInfo) context.getBean("server.sslInfo");
    log.info("JVM supportedCipherSuites: "
            + StringUtils.arrayToCommaDelimitedString(si.getSupportedCipherSuites()));
    log.info("JVM supportedProtocols: " + StringUtils.arrayToCommaDelimitedString(si.getSupportedProtocols()));
    log.info("default TrustManagerFactoryAlgorithm: " + si.getDefaultTrustManagerFactoryAlgorithm());

    // Start the Jetty
    ServerContainer sc = (ServerContainer) context.getBean("server.Container");
    sc.runUntilStopped();
}

From source file:com.ok2c.lightmtp.examples.SendMailExample.java

public static void main(final String[] args) throws Exception {

    if (args.length < 3) {
        System.out.println("Usage: sender recipient1[;recipient2;recipient3;...] file");
        System.exit(0);//  w w w.ja va 2s  .c om
    }

    String sender = args[0];
    List<String> recipients = new ArrayList<String>();
    StringTokenizer tokenizer = new StringTokenizer(args[1], ";");
    while (tokenizer.hasMoreTokens()) {
        String s = tokenizer.nextToken();
        s = s.trim();
        if (s.length() > 0) {
            recipients.add(s);
        }
    }

    File src = new File(args[2]);
    if (!src.exists()) {
        System.out.println("File '" + src + "' does not exist");
        System.exit(0);
    }

    DeliveryRequest request = new BasicDeliveryRequest(sender, recipients, new FileSource(src));

    MailUserAgent mua = new DefaultMailUserAgent(TransportType.SMTP, IOReactorConfig.DEFAULT);
    mua.start();

    try {

        InetSocketAddress address = new InetSocketAddress("localhost", 2525);

        Future<DeliveryResult> future = mua.deliver(new SessionEndpoint(address), 0, request, null);

        DeliveryResult result = future.get();
        System.out.println("Delivery result: " + result);

    } finally {
        mua.shutdown();
    }
}