I have two char arrays (e.g. arr[]1 {'w','o','r','d'} and arr[]2 {'o','r'}) and need to check for pattern occurrence of arr[]2 in arr[]1 (All values of arr2 must be present in arr1 in the same sequential order).
I already solved this by converting to strings and using regex. However, I was wondering if this could be solved without building strings consisting of the chars in each array.
Is it possible to check if an entire array is part of another one in JAVA (while keeping continuity/index sequence in account) or do I have to iterate through each value [n], [n+1],... [arr2.length] of arr2 and see if it is present in arr1[indexofFoundChar],[index+1]... and so on.
Any help is greatly appreciated.
String, but without regex:String.valueOf(arr1).contains(String.valueOf(arr2)).containsmethods, no need for regex... if you really need to do it yourself hava a look at the implementation ofcontains, or more precisely,indexOf()arr[1]1 {'w', 'o', 'x', 'r'}should it returntruefor abovearr[]2?