I have a String text "Welcome!to java@";
I know how to convert it to receive array [Welcome, to, java]
String[] aaa = text.split("[\\p{IsPunctuation}\\p{IsWhite_Space}]");
System.out.println(Arrays.toString(aaa)); //priinting
But I need to include punctuation. I need to receive [Welcome, !, to, java, @]
Anybody know who to receive it ?
The reason why I need to do it, because i have a randomise(char[] cw)
method, which is tweaking words for me. However that method is going crazy when punctuation is included
public void randomise(char[] cw)
{
for (int i = 1; i < cw.length-1; i++)
{
//my range
int range= (int)(Math.random() * (cw.length - i - 1));
//swap index
int index=i+range;
//swap
char temp = cw[i];
cw[i] = cw[index];
cw[index] = temp;
}
System.out.println(cw);
}
Thanks for reply