Sandeep Raj Urs Sandeep Raj Urs - 4 months ago 27
Java Question

Can anyone help me to get extra character by comparing 2 inputed strings by using java

.For example if i enter two strings ,say input1="sum" and input 2="su". I should get an output saying 'm' is the extra character present in a string.

public class odd {
public static void main(String[] args)
boolean b = false;
ArrayList<String> list= new ArrayList<String>();
ArrayList<String> list1= new ArrayList<String>();
String n1="sum";
String n2="su";
for(int i=1;i<n1.length();i++){
for(int j=1;j<n2.length();j++){
System.out.println("Extra character is "+n1.charAt(i));



One easy way you can do it if the only condition is to find the extra character added, is to use split. So in your case it would look something like this:

String string1 = "sum";
String string2 = "su";
String[] array1 = string1.split(string2);

This will print 'm'. And then you have to add conditions if you want to check which is the longer string etc. But this is a start.