We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Java
- Strings
- Java String Tokens
- Discussions
Java String Tokens
Java String Tokens
Sort by
recency
|
1722 Discussions
|
Please Login in order to post a comment
// worked
import java.util.Arrays; import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
} }
import java.util.*;
public class Solution {
public static void main(String[] args) { Scanner scan = new Scanner(System.in); String str = scan.nextLine(); tokens(str); } public static void tokens(String s){ s = s.trim(); String[] words = s.split("\P{L}+");
} }
can anybody tell me why trim() is required at all? the regex can handle the leading and trailing spaces but still when i am not using trim(), my code fails on a few test cases even after producing the exact same output as required for those cases! kinda confused
import java.io.; import java.util.;
public class Solution {
}