Example usage for java.util StringTokenizer nextToken

List of usage examples for java.util StringTokenizer nextToken

Introduction

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

Prototype

public String nextToken() 

Source Link

Document

Returns the next token from this string tokenizer.

Usage

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);/*from ww w.j a  v a2  s. c  om*/
    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:ReplacingStringTokenizer.java

public static void main(String[] args) {
    String input = "But I'm not dead yet! I feel happy!";
    StringTokenizer stoke = new StringTokenizer(input);
    while (stoke.hasMoreElements())
        System.out.println(stoke.nextToken());
    System.out.println(Arrays.asList(input.split(" ")));
}

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  .jav  a2 s  . c  o  m
}

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 ww w.j a  va 2 s  .co m
    }
    System.out.println(finalString);
}

From source file:Main.java

public static void main(String[] args) {
    int i = 0;//w  ww .  java  2  s . 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: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);/*from   ww  w .j  av  a2  s.  co 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: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 www.j  a v a 2s  .  c o m
    // 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:SubSupScriptPDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {/*from  w ww.ja v a2s  .  com*/
        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:StringBufferCommaList.java

public static void main(String[] args) {
    StringTokenizer st = new StringTokenizer("Alpha Bravo Charlie");
    StringBuffer sb = new StringBuffer();
    while (st.hasMoreElements()) {
        sb.append(st.nextToken());
        if (st.hasMoreElements()) {
            sb.append(", ");
        }// w  ww  .ja  v  a2 s.c o m
    }
    System.out.println(sb);
}

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   ww  w  .ja v a 2  s.  c om
    while (st.hasMoreTokens()) {
        token = st.nextToken();
        System.out.println(token);
    }
}