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 :: How to find a target value within a binary search tree, in Java? 
Java :: how to check if page in webview or not in android studio 
Java :: bloomreach remove property 
Java :: convert list to map java 
Java :: file to multipartfile in java 
Java :: android studio java toast 
Java :: xAxis.setTextSize() text gets clipped 
Java :: get last element of array java 
Java :: print arraylist java 
Java :: simulate mouse click java 
Java :: in a junit test how test if empty list is returned 
Java :: difference between offer and add in linkedlist in java 
Java :: java all alphabet characters 
Java :: Do not treat position as fixed; only use immediately and call `holder.getAdapterPosition()` to look it up later 
Java :: create map java 
Java :: how to clear activity stack in android 
Java :: android java display icon in action bar 
Java :: android onlcik java 
Java :: primefaces custom validation 
Java :: java split string on two or more spaces except for words in quotes 
Java :: android studio get string from strings.xml 
Java :: how to hide label in bottom menu android studio 
Java :: sreekanth kasani 
Java :: find duplicate value in array java 
Java :: android glide 
Java :: font type javafx button css 
Java :: java if one sting on array match 
Java :: spring jpa count all rows 
Java :: dagger dependency maven dependency 
Java :: how to iterate hashmap java 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =