• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help in String[]  RSS feed

 
adeeb alexander
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
i am struck up while performing an operation on the string array. Consider String[] a = new String [5] and another string String[] b=new String[3]. Now all the 'a' contains the values 0-6, and 'b' conatins values 0,1,9,4,7 respectively. So the first element of 'b' should be compared with all elements of 'a' and this goes on till the last index of 'b' is reached. Mean while if the element of 'b' is not matched with any of the elements in 'a' then it should return a null value.
Please see the below program you may understand my problem, i am able to match the values.

Actually i have to write the values to a file but only once i.e if the value is matched it is written to the file, till here it is fine. If a value is not matched then it should write null 1 time. My main problem is that the null value is written many times which i do not require i.e how many times the value is not matched that many times the null value is written. The actuall code is very lengthy, so i have made an example of my problem.Please some body help me out. The else block is used to write the null value

Thanks and Regards
alexander>
 
Michael Angstadt
Ranch Hand
Posts: 278
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code that writes to the file should not be inside the for loop that iterates over b. Instead, use the loop to find your match and do the file writing after the loop:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!