How to use comma and dot as delimiter in addition with Java default delimiter

后端 未结 3 1799
春和景丽
春和景丽 2021-01-14 06:33

I have a text file which contains lot of permutations and combinations of special characters, white space and data. I am storing the content of this file into an array list,

3条回答
  •  余生分开走
    2021-01-14 06:59

    The default delimiter for Scanner is defined as the pattern \p{javaWhitespace}+, so if you want to also treat comma and dot as a delimiter, try

    input.useDelimiter("(\\p{javaWhitespace}|\\.|,)+");

    Note you need to escape dot, as that is a special character in regular expressions.

提交回复
热议问题