'Getting error as char cannot be dereferenced in java
Getting char cannot be dereferenced error , while writing following code
for(int i =1;i<=m;i++){
for(int j =1;j<=l;j++){
if(A.charAt(i-1).equals(B.charAt(j-1))){
arr[i][j] = arr[i][j-1] + arr[i-1][j-1];
}
else{
arr[i][j] = arr[i][j-1];
}
}
}
on line if(A.charAt(i-1).equals(B.charAt(j-1)))
Solution 1:[1]
charAt returns a primitive char which does not have methods such as equals.
To compare primitives, you can use ==:
if(A.charAt(i-1) == B.charAt(j-1)) {
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | f1sh |
