Home Discussion Discuss: Convert Object To String

  • 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



Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Related Articles
Java Beginners

string object
string object  Hi, how do i write a program that works with a user's password, when the program should prompt the user for a possible password, that is between 6 and 10 characters long, that contains at least one letter 

Java Interview Questions

object
object  is it possible to create object in the same class..?.   Yes, you can. class CreateObject { CreateObject(){ System.out.println("I have an object."); } public static void main(String[] args 

Java Beginners

object 2 string - Java Beginners
object 2 string  hi sir,how to convert object to string and how 2 compare object with null value to string with null value plz provide a program 4 this sir,plzzzzzzzzz 

Java Tips and Examples

Convert Object To String
Convert Object To String       In this section, you will learn to convert an object to a string... in converting an object type data into a string type data. The toString() method 

Java Tips and Examples

Converting object to String
Converting object to String In this section you will learn to convert Object to String in java. It is sometimes necessary to convert object to String... to convert the object to string. public class ObjecttoString { public static 

Java Beginners

String and stringbuffer object - Java Beginners
String and stringbuffer object  Hi, What is the basic difference between string and stringbuffer object? Thanks   Hi Friend, Differences: 1)String class is used to manipulate character strings that cannot 

General

Convert an Integer type object to a String object
Convert an Integer type object to a String object       In this section you will learn to convert the Integer type object to a String object using the Integer.toBinaryString 

Programming Tutorials

Object representation in to String example
.style1 { font-size: medium; } Object representation in to String example:- We can represent any kind of object in the form of string...="110" title="Convert other object to String" 

Java Interview Questions

Object Creations
Object Creations  String a[][]=new String[10][20]; The above line how many objects are created 

Java Beginners

object array
object array  Hi i have array that is object[] obj= { new string("hi"), new vector().add(10), new hashmap().setkey()} display(obj); display(object{[] obj) {} Now my question is what is the string length and how to retrieve 

Java Interview Questions

Java object
Java object  What is mutable object and immutable object?  An Immutable object is a kind of object whose state cannot be modified after it is created. This is as opposed to a mutable object, which can be modified 

Java Technology Tutorials

Java date to String, Convert date object into a string with a pattern
Convert date object into a string with a pattern This section illustrates you the conversion of date object into a string pattern. Java has provide many... string. For example, d -  denotes the day in month M- denotes the month 

Java Beginners

constructor or object
constructor or object  object or construct which create first?  ... Example { Example(String st){ System.out.println(st); } public static void main(String[] args) { Example ex=new Example1("Hello 

Java Beginners

Vector object[]
Vector object[]  I want to create payslip in java public Vector...(); Object[] value = new Object[] {"Employee Name",f.ename.getSelectedItem()}; rec.add(value); value = new Object[] {"Mary-Kate Olsen", "Ashley 

Java Beginners

Class and object
"); } public static void main(String args[]) { A a = new B(); A a1 = new... the object of subclass Thanks 

WebSevices Questions

how to convert xml string to soap request object using axis1.4?
how to convert xml string to soap request object using axis1.4?  how to convert xml string to soap request object using axis1.4 

General

String intern()
() method returns a standard form representation of a string object. Basically... already contains a string equal to this String object as determined by the equals(Object) method then on invoking the intern method the string from the pool 

JDBC Questions

I retrieve a String or other object type without creating a new object each time.
I retrieve a String or other object type without creating a new object each time.  How can I retrieve a String or other object type without creating a new object each time 

Java Beginners

move an object
java.awt.*; public class MoveBall { public static void main(String[] args 

Java Beginners

ReadLine(String fmt,Object... args) of Console class - Java Beginners
ReadLine(String fmt,Object... args) of Console class  How to reload the string and objects of console class in Java?  Hi friend,import... ConsoleExample{ public static void main(String[] args){ Console console 

Java Interview Questions

String Ques
pool.It utilize memory in a better way with fulfilling object creation. While String st="abc" creates one object which goes to string pool.It consumes less memory. 2...") is a String Object. Thanks   Thank u very much 

Java Beginners

(ii) String and String Buffer Class
between String and StringBuffer 1) String object is immutable whereas StringBuffer objects are mutable. 2) String objects are constants...String and String Buffer Class  difference between String and String 

Java Beginners

conver object to int
conver object to int  i have a method returns object but i need int how can convert ? notice:object not means string means object string str map.get(str) returns object but i need an integer 

JSP Interview Questions

JSP Response Object
JSP Response Object  JSP response Object ?   The response object denotes the HTTP Response data. The result or the information of a request is denoted with this object. The response object handles the output 

JSP Interview Questions

JSP Application Object
Object: getAttribute(String name) getAttributeNames() setAttribute(String objName, Object object) removeAttribute(String objName) getMajorVersion...JSP Application Object  JSP Application Object?    

Java Beginners

string related
string related  As with any other object, you can create String objects by using the new keyword and a constructor. The String class has thirteen constructors that allow you to provide the initial value of the string using 

JSP Interview Questions

JSP Session Object
of session Object: getAttribute(String name) getAttributeNames() isNew... removeAttribute(String name) setAttribute(String, object...JSP Session Object  JSP Session Object?   Session Object 

JSP Interview Questions

JSP Request Object
) getQueryString() getRequestURI() getServletPath() setAttribute(String,Object...JSP Request Object  JSP Request Object ?   request object... an HTTP request. The request object is used to take the value from the client?s 

Java Beginners

vector object - Java Beginners
vector object  hi i have created a Vector vec=new Vector(); vec.addElement(o); o is an object of group(acl.group) what i have to do to read contents of this object? can it be possible to convert it into string arrays 

Java Tips and Examples

Convert Object to Int
Convert Object to Int       In this section, we are going to learn to convert a numeric string type...; Code Description: The following program converts numeric string type object 

DMCA.com