ShemSeger
7
Q:

split method in java

String yourString = "Hello/Test/World";
String[] strings = yourString.split("/" /*<- Regex */); 

Output:
strings = [Hello, Test, World]
8
String string = "004-034556";
String[] parts = string.split("-");
String part1 = parts[0]; // 004
String part2 = parts[1]; // 034556
17
// Java program to demonstrate 
// methods of Spliterator 
  
import java.util.ArrayList; 
import java.util.Spliterator; 
import java.util.stream.Stream; 
      
public class SpliteratorDemo  
{ 
    public static void main(String[] args)  
    { 
        // Create an array list for doubles. 
        ArrayList<Integer> al = new ArrayList<>(); 
              
        // Add values to the array list. 
        al.add(1); 
        al.add(2); 
        al.add(-3); 
        al.add(-4); 
        al.add(5); 
              
        // Obtain a Stream to the array list. 
        Stream<Integer> str = al.stream(); 
              
        // getting Spliterator object on al 
        Spliterator<Integer> splitr1 = str.spliterator(); 
          
        // estimateSize method 
        System.out.println("estimate size : " + splitr1.estimateSize()); 
                  
        // getExactSizeIfKnown method 
        System.out.println("exact size : " + splitr1.getExactSizeIfKnown()); 
          
        // hasCharacteristics and characteristics method 
        System.out.println(splitr1.hasCharacteristics(splitr1.characteristics())); 
          
        System.out.println("Content of arraylist :"); 
        // forEachRemaining method     
        splitr1.forEachRemaining((n) -> System.out.println(n)); 
          
        // Obtaining another  Stream to the array list. 
        Stream<Integer> str1 = al.stream(); 
        splitr1 = str1.spliterator(); 
          
        // trySplit() method 
        Spliterator<Integer> splitr2 = splitr1.trySplit(); 
          
        // If splitr1 could be split, use splitr2 first. 
        if(splitr2 != null) { 
        System.out.println("Output from splitr2: "); 
        splitr2.forEachRemaining((n) -> System.out.println(n)); 
        } 
  
        // Now, use the splitr 
        System.out.println("\nOutput from splitr1: "); 
        splitr1.forEachRemaining((n) -> System.out.println(n)); 
              
    } 
} 
1
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); 
    } 
}
6
// Java program to demonstrate working of split(regex, 
// limit) with small limit. 
public class GFG { 
    public static void main(String args[]) 
    { 
        String str = "geekss@for@geekss"; 
        String[] arrOfStr = str.split("@", 2); 
  
        for (String a : arrOfStr) 
            System.out.println(a); 
    } 
} 
9
String textfile = "ReadMe.txt";
String filename = textfile.split(".")[0];
String extension = textfile.split(".")[1];
0
String textfile = "ReadMe.txt";
String filename = textfile.split("\\.")[0];
String extension = textfile.split("\\.")[1];
0

New to Communities?

Join the community