Avatar ·

How to split a string into parts in Java? Using split()

Hello everyone! I'm a beginner in Java and ran into a problem. I need to split a string into individual words or parts by some delimiter. For example, I have a string: ```java String data = "apple,banana,orange,pear"; ``` I want to get an array of these fruits: `["apple", "banana", "orange", "pear"]`. I tried using the `split()` method, but I don't fully understand how it works. I wrote this code: ```java String[] fruits = data.split(","); ``` It seems to work, but when I try to split a string with a dot, for example `"Hello.World"`: ```java String[] parts = "Hello.World".split("."); ``` The array turns out empty! Why is that? And how to properly split strings in Java? I'm also interested in what to do if there are multiple delimiters in a row (for example, a double comma) and