First way:
- You can first break your line based on
::: . This will give you an array of length 3. You will be interested in the 2nd and 3rd element of your array. - Then divide the
2nd element your array by :: . This will give you an array containing each name . Go through the 2nd array and type each name with the 3rd element your first array.
String str = "books/eh/grayL88/WilliamsMC88:::M. Howard Williams::" + "PA Massey::Jim A. Crammond:::Benchmarking Prolog for " + "Database Applications."; String[] arr = str.split(":::"); String[] innerArr = arr[1].split("::"); for (String name: innerArr) { System.out.println(name + " -- " + arr[2]); }
OUTPUT : -
M. Howard Williams - Trial Test for Database Applications.
PA Massey - Benchmarking Prolog for Database Applications.
Jim A. Crummond - Trial Protocol for Database Applications.
The second way:
Or can you divide by :::? . This will be split into :: or ::: , which will receive every single element only in your first array (will only work for names 3 For more, you better use the first)
String[] arr = str.split(":::?"); System.out.println(arr[1] + " - " + arr[4]); System.out.println(arr[2] + " - " + arr[4]); System.out.println(arr[3] + " - " + arr[4]);
OUTPUT : -
M. Howard Williams - Benchmarking Prolog for Database Applications. A. Massey - Trial protocol for database applications.
Jim A. Crammond - Trial Protocol for Database Applications.
source share