Extract String in Java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Extract String in Java

I want to extract only certain portion of String followed by = sign The string is “[AlbumId=1, CategoryId=1, albumTitle=DJ NYK, hirePrice=20, noofCD=5, status=Available]” From here I want to extract "1","1","DJ NYK","20",5,"Available" .I have tried with split() but I cannot extract properly .Will be highly grateful if I receive any help

3rd Jul 2022, 2:11 PM
notstacked‎
notstacked‎ - avatar
2 Answers
+ 4
notstacked You can first split string on comma (,) then after splitting string will be convert in array of string. Now use for loop and split each string of that new array with equal (=) Here is an example: String str = "1=2, 3=4, 5=6"; String [] arr = str.split(", "); for (String s : arr) { String[] a = s.split("="); System.out.println(a[1]); }
3rd Jul 2022, 2:26 PM
A͢J
A͢J - avatar
+ 1
Thank you so much A͢J
3rd Jul 2022, 8:06 PM
notstacked‎
notstacked‎ - avatar