I'v done this with a program recently in hope that I could convert an Object into a String and then compare 2 String type variables in an if statement, but for whatever reason the variable that was originally an Object (but now a String) is not being picked up
eg
cpuChoice = objectChoice.toString();
if((playerChoice.equalsIgnoreCase("Rock")&&(cpuChoice.equals("Rock"))){
System.out.println("the game is a tie");
}
etc etc
however if I force cpuChoice to "Rock" then the if statement works perfectly, any ideas?
String str=o.toString();
System.out.println(str+" is found at index "+search(arr, o)+".");}
My "o" is "hello". The search method will return "2".
My output is:
[Ljava.lang.String;@19189e1 is found at index 2.
helplalarargh April 17, 2012 at 10:22 PM
I'v done this with a program recently in hope that I could convert an Object into a String and then compare 2 String type variables in an if statement, but for whatever reason the variable that was originally an Object (but now a String) is not being picked up eg cpuChoice = objectChoice.toString(); if((playerChoice.equalsIgnoreCase("Rock")&&(cpuChoice.equals("Rock"))){ System.out.println("the game is a tie"); } etc etc however if I force cpuChoice to "Rock" then the if statement works perfectly, any ideas?
This didn't work for me.Dan December 4, 2012 at 12:19 AM
String str=o.toString(); System.out.println(str+" is found at index "+search(arr, o)+".");} My "o" is "hello". The search method will return "2". My output is: [Ljava.lang.String;@19189e1 is found at index 2.
Post your Comment