Edit2: : I have main data(list or array,it's no matter) like this:
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}
I want to:
1-replace all values containing 3 with "julie"
2-all values that are val % 15 == 0 should be replaced with "jack".
3-also replace all values that are val % 5 == 0 should be replaced with "john" ,
Note: Without If Else Just With Java 8.
In the end I should have this data :
("1","2","julie","4","john","6","7","8","9","john","11","12","julie","14","jack","16","17","18","19","john")
for this issue I use stream and replaced these values with related string and i created 3 related list for each string:
1-Result for need1(replace all values containing 3 with "julie"):
("1","2","julie","4","5","6","7","8","9","10","11","12","julie","14","15","16","17","18","19","20")
2-Result for need2(all values that are val % 15 == 0 should be replaced with "jack"): ("1","2","3","4","5","6","7","8","9","10","11","12","13","14","jack","16","17","18","19","20")
3-Result for need3(replace all values that are val % 5 == 0 should be replaced with "john") :("1","2","3","4","john","6","7","8","9","john","11","12","13","14","john","16","17","18","19","john")
Now I want to have a final result such as below(either with mereg these lists or any other method without If&Else just with java8): :
("1","2","julie","4","john","6","7","8","9","john","11","12","julie","14","jack","16","17","18","19","john")
Thanks!
val % 15 == 0should be replaced with"jack"- then why"jack"appear in place of2and9?just the string fields must be replaced with pure value- this phrase is not clear at all. By looking at example of the resulting list I assume that you need to obtain a list of the same size as previous three, and at each position where names like"john","julie"or"jack"appear in one of the lists they should take residence over the numbers. Where this guessing is correct or not you should edit the question to clarify it. And it is still not clear how resolve the case when two name would appear at the same position. Both"john"and"jack"would clash at index15.