My code looks like below,
string filename = '/*testfile /*testfile'; List<String> parts = filename.split('/*');
Expected output :
t e s ..
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.Sign up to join this community
Split actually expects a regular expression, so your split string is interpreted as "split when there are zero or more / characters" ("*" means "zero or more").
To avoid this behavior, you have to "escape" the "*" character with a backslash, which itself needs to be escaped with a backslash:
List<String> parts = filename.split('/\\*');
Without that escape, it tries to split every character from every other character, with the slash ("/") being stripped out entirely.
If you look at the String methods, the documentation tells you this explicitly:
Returns a list that contains each substring of the String that matches this pattern.
public String split(String regExp)