cancel
Showing results for 
Search instead for 
Did you mean: 

help Java function

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

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

Former Member
0 Kudos

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.