hehehe sorry, but ... this is funny.
There is no way to know, because you don't have any other identifier to delimit your resulting string. Have you use another separator It might work, but the way your problem is "specified" as of now, there is nothing much you can do about it.
So, if this is homework, I would suggest you to call your teacher and ask him: "What are you to do if there is > 10 occurences"
Unless it is explicitly forbidden in your specifications. I would add an space to the resulting string. So the output would be:
0 0 0 10 0 0
Instead of
0001000
EDIT
if i put space and try to convert this string into INT to do SUM it give error :(
Well don't include the space then:
String a = "0 0 9 0";
String b = "0 0 9 0";
String [] pa = a.split(" ");
String [] pb = b.split(" ");
StringBuilder result = new StringBuilder();
for( int i = 0 ; i < pa.length; i++ ) {
result.append( Integer.parseInt( pa[i] ) + Integer.parseInt( pb[i] ) );
result.append( ' ' );
}
System.out.println( r );
Prints:
0 0 18 0
Without ambiguities.
Still I really think that you need a different data structure, if the only reason you're using strings, is because you can store them in files, for later processing, then, you can still change from data strucure. You can use an arrya or something similar in memory and eventually persist it to any representation you like ( I would use object serialization directly )
Once you need to process more information you retrieve your stored data and load it again in memory.
You may consider using a Map
where as key you use the word and as value the count:
Something like this
public void add( String s ) {
if( !map.containsKey( s ) ){
map.put( s, 0 );
}
map.put( s, map.get( s ) + 1 );
}
Each time you find a word, you call this method and that will increase the count in memory.
All your previous questions look really interesting, I think you are stopping just by some technical details. Use a different data structure and continue with your research.