Skip to Content
author's profile photo Former Member
Former Member

help Java function

Hi

I want to code a function which comapres an array that contains "X" or empty values,with an array which contains only "X" and return a boolean array with boolean arguments (true/false)

any ideas?

Thx,Shai

Add comment
10|10000 characters needed characters exceeded

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Aug 03, 2006 at 07:22 AM

    Hi Shai,

    Following code will help you,

    String arr_1[] = {"X", "", "X", ""};

    String arr_2[] = {"X", "X", "X", "X"};

    boolean arr_3[] = new boolean[arr_1.length];

    foo(arr_1, arr_2, arr_3);

    where the function could be like,

    void foo(String[ ] arr_1, String[ ] arr_2, boolean[ ] arr_3 ) {

    for(int i=0; i<arr_1.length; i++) {

    if( arr_1[ i ] != null && arr_2[ i ].equalsIgnoreCase (arr_1[ i ]) ) {

    arr_3[ i ] = true;

    } else {

    arr_3[ i ] = false;

    }

    }

    }

    I hope this will help you.

    Regards,

    Guru.

    PS: Award points for helpfull replies.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 03, 2006 at 07:22 AM

    Hi Shai,

    This is the code that you had asked for . This method returns an array of booleans .

    public boolean[] comparison()
    	{
    		String[] firstArray = {"X","X",""};
    		String[] secondArray = {"X","X","X"};
    		int lengthOfFirstArray = firstArray .length;
    		int lengthOfSecondArray = secondArray.length;
    		int lengthOfResultantArray = Math.max(lengthOfFirstArray,lengthOfSecondArray);
    		boolean[] resultantArray = new boolean[lengthOfResultantArray];
    		for (int countCharacter=0;countCharacter<firstArray.length;countCharacter++ )
    		{
              if(firstArray[countCharacter].equals(secondArray[countCharacter]))
    			{
    			  resultantArray[countCharacter] = true;
    			}
              else{
    			  resultantArray[countCharacter] = false;
    		  }
    		}
    		return resultantArray;
    	}

    Regards,

    Tahzeeb

    Add comment
    10|10000 characters needed characters exceeded