File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Comparing chars at positions in an array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Comparing chars at positions in an array" Watch "Comparing chars at positions in an array" New topic
Author

Comparing chars at positions in an array

Shaggy Rogers
Greenhorn

Joined: Mar 10, 2006
Posts: 26
Hello all, I'm coding something like

for(int i = 0; i < maze.length; i++)
{
for(int x = 0; x < maze[0].length; x++)
{
if(maze[i][x] == ('.'))
{
maze[i][x] == ('!');
}
System.out.print(maze[i][x]);
}

that finds a '.' char in a 2D array and replaces it with a '!' character. However, using == does not work. I have tried using .equals as well and get a dereferencing error. Any help on how to compare the characters would be greatly appreciated, thanks.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18978
    
  40

This is nothing wrong with the comparison. It is the assignment that is incorrect. Don't you mean this...


The "==" is not a valid assignment operator.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Did you mean for the second == to be =?
Shaggy Rogers
Greenhorn

Joined: Mar 10, 2006
Posts: 26
>_<
THanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Comparing chars at positions in an array