Converting string of an array back to array

Tags:



I have this string : "[ name = preload cacheHits = 0 onDiskHits = 0 inMemoryHits = 0 misses = 0 size = 0 averageGetTime = 0.0 evictionCount = 0 ]",

and want to convert it in array like [ name = preload cacheHits = 0 onDiskHits = 0 inMemoryHits = 0 misses = 0 size = 0 averageGetTime = 0.0 evictionCount = 0 ],

How can we do it?

Answer

String response="[ name = preload cacheHits = 0 onDiskHits = 0 inMemoryHits = 0 misses = 0 size = 0 averageGetTime = 0.0 evictionCount = 0 ]";
String replace = response.replaceAll("^\[|]$","");
System.out.println(Arrays.asList(replace));


Source: stackoverflow