AndreaF
AndreaF

Reputation: 12395

Tokenize multiple String in array if the input sometimes doesn't have token

I have input in this form

[email protected]

and\or in this form

[email protected];[email protected]

or

[email protected];[email protected];[email protected]

I should tokenize all, in a String array that contains only a single email for each cell without any separator

;

Upvotes: 2

Views: 430

Answers (1)

Maurício Linhares
Maurício Linhares

Reputation: 40333

You don't want to tokenize, just use split:

String[] emails = { "[email protected];[email protected];[email protected]", "[email protected]"  };
List<string> result = new ArrayList<String>();

for ( string listOfEmails : emails ) {
  for( string email : listOfEmails.split(";") ) {
    result.Add(email).
  }
}

System.out.println(result);

And it will work for all cases.

Upvotes: 3

Related Questions