Skip to main content
added 2 characters in body
Source Link
Roman C
  • 1
  • 33
  • 71
  • 194

I need to send an integer array and a string array to this generic method and find out if a certain number or string is present there or not.I wrote this code but it is giving an error on the line if(e==30) saying that "Incompatible operand types E and int""Incompatible operand types E and int". Please help.

public class Ch2Lu3Ex2 { public static <E> void searchArray(E[] inputArray) { for(E e : inputArray) { if(e==30) { System.out.println("Element found in integer array"); } else if(e=="raj") { System.out.println("Element found in string array"); } } } public static void main(String[] args) { Integer[] integerArray = {10,20,30}; String[] stringArray = {"robin","raj","ravi"}; searchArray(integerArray); searchArray(stringArray); } } 

I need to send an integer array and a string array to this generic method and find out if a certain number or string is present there or not.I wrote this code but it is giving an error on the line if(e==30) saying that "Incompatible operand types E and int". Please help.

public class Ch2Lu3Ex2 { public static <E> void searchArray(E[] inputArray) { for(E e : inputArray) { if(e==30) { System.out.println("Element found in integer array"); } else if(e=="raj") { System.out.println("Element found in string array"); } } } public static void main(String[] args) { Integer[] integerArray = {10,20,30}; String[] stringArray = {"robin","raj","ravi"}; searchArray(integerArray); searchArray(stringArray); } } 

I need to send an integer array and a string array to this generic method and find out if a certain number or string is present there or not.I wrote this code but it is giving an error on the line if(e==30) saying that "Incompatible operand types E and int". Please help.

public class Ch2Lu3Ex2 { public static <E> void searchArray(E[] inputArray) { for(E e : inputArray) { if(e==30) { System.out.println("Element found in integer array"); } else if(e=="raj") { System.out.println("Element found in string array"); } } } public static void main(String[] args) { Integer[] integerArray = {10,20,30}; String[] stringArray = {"robin","raj","ravi"}; searchArray(integerArray); searchArray(stringArray); } } 
edited tags
Link
Andremoniy
  • 35.2k
  • 25
  • 143
  • 259
added 1 characters in body
Source Link
Roman C
  • 1
  • 33
  • 71
  • 194

I need to send an integer array and a string array to this generic method and find out if a certain number or string is present there or not.I wrote this code but it is giving an error on the line "if(e==30)"if(e==30) saying that "Incompatible operand types E and int".Please Please help.

public class Ch2Lu3Ex2 { public static <E> void searchArray(E[] inputArray) { for(E e : inputArray) { if(e==30) { System.out.println("Element found in integer array"); } else if(e=="raj") { System.out.println("Element found in string array"); } } } public static void main(String[] args) { Integer[] integerArray = {10,20,30}; String[] stringArray = {"robin","raj","ravi"}; searchArray(integerArray); searchArray(stringArray); } } 

I need to send an integer array and a string array to this generic method and find out if a certain number or string is present there or not.I wrote this code but it is giving an error on the line "if(e==30)" saying that "Incompatible operand types E and int".Please help.

public class Ch2Lu3Ex2 { public static <E> void searchArray(E[] inputArray) { for(E e : inputArray) { if(e==30) { System.out.println("Element found in integer array"); } else if(e=="raj") { System.out.println("Element found in string array"); } } } public static void main(String[] args) { Integer[] integerArray = {10,20,30}; String[] stringArray = {"robin","raj","ravi"}; searchArray(integerArray); searchArray(stringArray); } } 

I need to send an integer array and a string array to this generic method and find out if a certain number or string is present there or not.I wrote this code but it is giving an error on the line if(e==30) saying that "Incompatible operand types E and int". Please help.

public class Ch2Lu3Ex2 { public static <E> void searchArray(E[] inputArray) { for(E e : inputArray) { if(e==30) { System.out.println("Element found in integer array"); } else if(e=="raj") { System.out.println("Element found in string array"); } } } public static void main(String[] args) { Integer[] integerArray = {10,20,30}; String[] stringArray = {"robin","raj","ravi"}; searchArray(integerArray); searchArray(stringArray); } } 
Source Link
Robin
  • 143
  • 10
Loading