You are here : Home / Core Java Tutorials / Interview Programs (beginner to advanced) in java / Level2 programs in java (intermediate)
In this core java programming tutorial we will write a program to Find whether all characters of string appear in the inputString in same order in java .
inputString : wbaodralrd
findString : world
you are given an string ”world”. write a program to find whether “wbaodralrd” contains all character of string"world" in same order as they appear in "world" the method will return true if the “wbaodralrd” contains all letter in same order.
Full Program/SourceCode/ Example to find whether all characters of string appear in the inputString in same order in java >
/** Copyright (c), AnkitMittal JavaMadeSoEasy.com */
public class CheckContinuityOfString {
public static void main(String[] args) {
String inputString="wbaodralrd";
String findString="world";
System.out.println(checkContinuity(inputString,findString) ==true ? "TRUE":"FALSE");
}
/**
* returns true if required condition matches.
*/
static boolean checkContinuity(String inputString, String findString){
char inputCh[]=inputString.toCharArray();
char findCh[]=findString.toCharArray();
int pos=0;
for(int i=0;i<inputCh.length;i++){
if(inputCh[i]==findCh[pos]){
pos++;
if(pos==findCh.length)
return true;
}
}
return false;
}
}
/*OUTPUT
TRUE
*/
|
So in this core java programming tutorial we learned how to write a program to find whether all characters of string appear in the inputString in same order in java .
RELATED LINKS>