In this program we iterate String with for loop. after that convert string to character and add to String Builder class.
public class MergeStringWithWord {
public static void main(String[] args) {
String s1 = "well";
String s2 = "come";
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s2.length() || i < s1.length(); i++) {
if (i < s1.length()) {
sb.append(s1.charAt(i));
}
if (i < s2.length()) {
sb.append(s2.charAt(i));
}
}
System.out.println("Merge word is:- " + sb);
}
}
Output:-
Merge word is:- wceolmle