How to split string by multiple character delimiter in Java

1 Answer

0 votes
public class SplitStringByMultipleCharacterDelimiter_Java {
    public static void main(String[] args) {
        String s = "c#!java,@c!php*,python";

        String[] arr = s.split("[,@!*]+");

        for (String word : arr) {
            System.out.println(word);
        }
    }
}


        
/*
run:

c#
java
c
php
python
    
*/

 



answered Sep 14, 2024 by avibootz

Related questions

1 answer 128 views
1 answer 114 views
1 answer 115 views
1 answer 1,706 views
2 answers 268 views
1 answer 106 views
...