• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

setText(String);

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
int a =(Integer.parseInt(t1.getText()) + Integer.parseInt(t2.getText()));
t3.setText(a);/// error

t3.setText(""+a);//works fine. WHY???

how do you convert int to string
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The String concatenation operator is overloaded to take an operand of type int (actually any operand type). The result of the concatenation is always of type String.
 
Anirudha Jadhav
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
thanks for your reply,
I would like to know how do make the statement work with out the String concatenation operator.
thanking you...
 
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Anirudha Jadhav:
hi
thanks for your reply,
I would like to know how do make the statement work with out the String concatenation operator.
thanking you...



Here's the thing, at the end, your setting the text, so no matter what, it's going to be a textual representation. You could do something like this.

Integer i = new Integer(int);
t3.setText(i.toString());
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And what is the type of t3? Maybe you should look at the API to see if that object's class takes an int as a formal argument. If it only takes a String then you have already solved your own problem, the actual argument can be "" + i, or use the static method Integer.toString(i).
 
The moustache of a titan! The ad of a flea:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic