YouTip LogoYouTip

Java Stringtokenizer Example

# Java Example - String Separation (StringTokenizer) [![Image 3: Java Example](#) Java Example](#) In Java, we can use StringTokenizer to separate strings with different delimiters. The default delimiters are: space, tab (t), newline (n), and carriage return (r). The following example demonstrates using StringTokenizer to separate a string with spaces and equals signs: **For more information on StringTokenizer, see: (#)** ## JavaStringSplitEmp.java File import java.util.StringTokenizer; public class Main{public static void main(String[]args){String str = "This is String , split by StringTokenizer, created by tutorial"; StringTokenizer st = new StringTokenizer(str); System.out.println("----- Separated by spaces ------"); while(st.hasMoreElements()){System.out.println(st.nextElement()); }System.out.println("----- Separated by commas ------"); StringTokenizer st2 = new StringTokenizer(str, ","); while(st2.hasMoreElements()){System.out.println(st2.nextElement()); }}} Output: ----- Separated by spaces ------ThisisString, split byStringTokenizer, created by tutorial ----- Separated by commas ------This is String split by StringTokenizer created by tutorial [![Image 4: Java Example](#) Java Example](#)
← Vue StartMacos Docker Install β†’