Skip to content
Advertisement

Converting string of an array back to array

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?

Advertisement

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));
Advertisement