Possible Duplicate:
How do I compare strings in Java?
I have an array of String
s, the array is called Morse
:
private final static String[] Morse = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....",
"..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-",
"...-" ,".--" ,"-..-", "-.--", "--..",".-.-.-","--..--","..--.." ,"|"};
private final static String[] Colours = {"red","green","white"};
Then there is my code:
char[] stringArray;
stringArray = converttoMorse(letter).toCharArray();
char ch;
for(int i=0;i<stringArray.length;++i)
{
if(stringArray[i]== "." ) //Problem here
{
System.out.println(Colours[0]);
}
else if (stringArray[i] == "-" ) //Problem here
{
System.out.println(Colours[1]);
}
else
{
System.out.println(Colours[2]);
}
}
This is only a snippet of my actual program, the english to morse is working absolutely perfect. HOWEVER, I would like to indicate the dots and dashes as colors "red" and "green" respectively as string (with spaces indicating white).
I used the toCharArray()
method to breakdown the printed outcome Morse as an array. However I'm not able to correspond each of these dots and dashes to their specific colours. For example, I would like ".-"
to show as "red green"
. How can I do this? Is there a specific method for doing so?