Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to decompose a string into words in Java

import java.util.*;
public class CodeGrepper {
    public static void main(String[] args) {
        String strToDecompose = "Some sample text";
        // Use Scanner class to decompose String
        Scanner scan = new Scanner(strToDecompose);
        // hasNext(): return trues if there are more words 
        // next(): retrieves the next word
        while(scan.hasNext()) 
            System.out.print(scan.next() + "/"); // Some/sample/text/
        scan.close();
        System.out.println();
        // Using StringTokenizer to decompose String
        StringTokenizer st = new StringTokenizer(strToDecompose);
        // hasMoreTokens(): return true if there are more words
        // nextToken(): retrieves the next word
        while(st.hasMoreTokens())
            System.out.print(st.nextToken() + "/"); // Some/sample/text/ 
    }
}
Comment

string to words java

String[] words = string.split("s+");
Comment

PREVIOUS NEXT
Code Example
Java :: transparent border of jtextfield in java 
Java :: Java Create a ByteArrayInputStream 
Java :: java clear scanner2 
Java :: How to efficiently find the diameter of a binary tree, in Java? 
Java :: input char arrayjava 
Java :: java use parent method 
Java :: prime factorization java 
Java :: javadoc commands 
Java :: java programme for fibonnaci series 
Java :: permutation and combination program in java 
Java :: how to change background color of grid in grid layout in android 
Java :: fibonacci of 6 
Java :: firebase realtime database get key 
Java :: java double 
Java :: random number 
Java :: run java file 
Java :: groovy if else 
Java :: java multi thread 
Java :: Java @Deprecated annotation 
Java :: edittext editable false android java 
Java :: Java Expression statements 
Java :: set up a tree in java 
Java :: java sort reverse lambda 
Java :: Declaring a Java Method 
Java :: run jar file with different jre 
Java :: java 8 lambda comparator 
Java :: java "-" 
Java :: combobox index out of bound javafx 
Java :: how todo a timeout test java 
Java :: java and python begineers mcq with answers 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =