By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,387 Members | 1,729 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,387 IT Pros & Developers. It's quick & easy.

how to compare between two array of character arrays

P: 7
hi all!!
can any one please help me in checking the two character arrays.
in my code i need to compare a character array(seq) to that of hydrob and hydrop . if the seq has hydrob then it should be given a different colour. if it has a hydrop then it should be assigned a different colour. if the sequence does not have a character that is neither in hydrob and hydrop then they shuld be given a separate colour.
Expand|Select|Wrap|Line Numbers
  1. for (int i=0;i<seqlength;i++)//a for loop to get a letter 
  2.         {   
  3.             char str1 = seq[i]; // getting the first letter from 
  4.  
  5.             for (int j=0;j<hydroblen;j++)//for loop to check the
  6.             {  
  7.                 if (str1 == hydrob[j])//checking problem in here (suppose)
  8.                 {
  9.                    res=1;//setting a value
  10.                    System.out.println("reach") ;
  11.                    repaint();//calling d paint function to paint in 
  12.                    //System.out.println("reach") ;
  13.                    //j++;
  14.                 } 
  15.             } 
  16.         }
  17.         System.out.println("over") ;
  18.         for (int i=0;i<seqlength;i++)
  19.         {
  20.             char str2 = seq[i];
  21.                 for (int k =0;k<hydroplen;k++)                    
  22.                 {
  23.  
  24.                    while(str2==hydrop[k])
  25.                 {                    
  26.                     res =0;
  27.                     repaint();
  28.                     k++;
  29.                     System.out.println("reach") ;
  30.                 }
  31.                 }
  32.  
  33.         }
  34.  
  35.  
  36. i have compared them using this. but this is not much efficient which just paints the hydrophilic sequence lenght and paints the seq for that length of sequence. 
  37.  
  38. also the if loop in the paint function which have to do the paint for hydrob is not executing.
  39.  
  40. if(res==1)
  41.         {
  42.             gc.drawString(s, 700,700) ;// not executing the loop
  43.              for (int i =0;i<seqlength;i++)
  44.          {
  45.            gc.drawString(s, 700,700) ;  //to check whether the loop s executing.
  46.         for (int j=0; j><hydroblen;j++)
  47.         {       
  48.             x[i]= x0 + radius*Math.sin(theta*(i));
  49.             y[i]= y0 - radius*Math.cos(theta*(i));
  50.             X[i] = (int) x[i];
  51.             Y[i]= (int) y[i];
  52.             gc.fillOval(X[j]-7,Y[j]-7,14,14);
  53.             seq1 = seq[i] + "";
  54.             hydrop1 = hydrop[j]+"";
  55.             gc.drawString(seq1, X[i], Y[i]-8); 
  56.             gc.drawString("",X[j], Y[j]-8);
  57.             gc.drawLine(X[j],Y[j],X[j+1],Y[j+1]);
  58.             gc.setColor(Color.yellow);
  59.  
Apr 11 '07 #1
Share this Question
Share on Google+
4 Replies


hirak1984
100+
P: 316
so whr is da problem ?
hi all!!
can any one please help me in checking the two character arrays.
in my code i need to compare a character array(seq) to that of hydrob and hydrop . if the seq has hydrob then it should be given a different colour. if it has a hydrop then it should be assigned a different colour. if the sequence does not have a character that is neither in hydrob and hydrop then they shuld be given a separate colour.
Expand|Select|Wrap|Line Numbers
  1. for (int i=0;i<seqlength;i++)//a for loop to get a letter 
  2.         {   
  3.             char str1 = seq[i]; // getting the first letter from 
  4.  
  5.             for (int j=0;j<hydroblen;j++)//for loop to check the
  6.             {  
  7.                 if (str1 == hydrob[j])//checking problem in here (suppose)
  8.                 {
  9.                    res=1;//setting a value
  10.                    System.out.println("reach") ;
  11.                    repaint();//calling d paint function to paint in 
  12.                    //System.out.println("reach") ;
  13.                    //j++;
  14.                 } 
  15.             } 
  16.         }
  17.         System.out.println("over") ;
  18.         for (int i=0;i<seqlength;i++)
  19.         {
  20.             char str2 = seq[i];
  21.                 for (int k =0;k<hydroplen;k++)                    
  22.                 {
  23.  
  24.                    while(str2==hydrop[k])
  25.                 {                    
  26.                     res =0;
  27.                     repaint();
  28.                     k++;
  29.                     System.out.println("reach") ;
  30.                 }
  31.                 }
  32.  
  33.         }
  34.  
  35.  
  36. i have compared them using this. but this is not much efficient which just paints the hydrophilic sequence lenght and paints the seq for that length of sequence. 
  37.  
  38. also the if loop in the paint function which have to do the paint for hydrob is not executing.
  39.  
  40. if(res==1)
  41.         {
  42.             gc.drawString(s, 700,700) ;// not executing the loop
  43.              for (int i =0;i<seqlength;i++)
  44.          {
  45.            gc.drawString(s, 700,700) ;  //to check whether the loop s executing.
  46.         for (int j=0; j><hydroblen;j++)
  47.         {       
  48.             x[i]= x0 + radius*Math.sin(theta*(i));
  49.             y[i]= y0 - radius*Math.cos(theta*(i));
  50.             X[i] = (int) x[i];
  51.             Y[i]= (int) y[i];
  52.             gc.fillOval(X[j]-7,Y[j]-7,14,14);
  53.             seq1 = seq[i] + "";
  54.             hydrop1 = hydrop[j]+"";
  55.             gc.drawString(seq1, X[i], Y[i]-8); 
  56.             gc.drawString("",X[j], Y[j]-8);
  57.             gc.drawLine(X[j],Y[j],X[j+1],Y[j+1]);
  58.             gc.setColor(Color.yellow);
  59.  
Apr 11 '07 #2

Expert 10K+
P: 11,448
May I suggest a Set<Character> and let auto(un)boxing do the rest? Sets have
very convenient methods (removeAll, retainAll etc.) so it'll be extremely easy
to determine whether or not a char is present in two char arrays.

kind regards,

Jos
Apr 11 '07 #3

P: 7
May I suggest a Set<Character> and let auto(un)boxing do the rest? Sets have
very convenient methods (removeAll, retainAll etc.) so it'll be extremely easy
to determine whether or not a char is present in two char arrays.

kind regards,

Jos
hello jos,

thanks for your guidence but i cant get what you want to implemnt and where it should be done.
is there any other method to do by slightly modifying the code that ive written....?

thanks again
reva
Apr 11 '07 #4

P: 7
so whr is da problem ?
hello hirak,
thanks for your reply
the problem is in comparing the two arrays. in the if(str1 == hydrob[j]) which is not efficient to compare the arrays and results in false results.

thanks
reva
Apr 11 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.