Groovy : tokenize() vs split()
- The split() method returns a string [] instance and the tokenize() method returns a list instance
- tokenize() ,which returns a list, will ignore empty string (when a delimiter appears twice in succession) where as split() keeps such string.
[java]
String testString = ‘hello brother’
assert testString.split() instanceof String[]
assert [‘hello’,’brother’]==testString.split() //split with no arguments
assert[‘he’,”,’o brother’]==testString.split(‘l’)
// split keeps empty string
assert testString.tokenize() instanceof List
assert [‘hello’,’brother’]==testString.tokenize() //tokenize with no arguments
assert [‘he’,’o brother’]==testString.tokenize(‘l’)
//tokenize ignore empty string
[/java] - The tokenize() method uses each character of a String as delimiter where as split() takes the entire string as delimiter
[java]
String testString=’hello world’
assert [‘hel’,’ world’]==testString.split(‘lo’)
assert [‘he’,’ w’,’r’,’d’]==testString.tokenize(‘lo’)
[/java] - The split() can take regex as delimiter where as tokenize does not.
[java]
String testString=’hello world 123 herload’
assert[‘hello world ‘,’ herload’]==testString.split(/\d{3}/)
[/java]Feel free to ask our grails developers, if you have any queries
It’s spelled “delimiter”.
Hi there, ϒoս’vе doone a fantastіс job. I’ll definitely digg it and
personally recommmend to my friends. I am sure they’ll be benefited from this website.
En este lugar podrás localizar trucos para juegos de tu consola
preferida, Ordenador, Playstation, Playstation dos, PSP, Xbox,
Xbox 360, Nintendo DS. Registrate y publica los trucos que conozcas de tus juegos preferidos de cualquiera
de las consolas de nuestra sección de trucos
y trampas para juegos (Ordenador, Playstation, Playstation 2,
PSP, Xbox, Xbox 360, Nintendo DS). Acá los cuentas con, listos para oír y descargar para
tu teléfono móvil.