Answers for "split method not working in java"

13

split method in java

public class SplitExample2 { 
    public static void main(String args[]) 
    { 
        String str = "My name is Chaitanya";
        //regular expression is a whitespace here 
        String[] arr = str.split(" "); 
  
        for (String s : arr) 
            System.out.println(s); 
    } 
}
Posted by: Guest on May-23-2020
0

java string.split with . wont work

//Java

String sentence = "Hello World.How are you?";
String[] newSentence = sentence.split("\\.");
String firstString = newSentence[0];
String secondString = newSentence[1];
System.out.println(firstString + ' ' + secondString);
Posted by: Guest on January-05-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language