Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Int to String  RSS feed

 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I want to make


from an int to a string could I just do:



I think that may not be 100% correct but is that going to be the way to go about it?
 
Campbell Ritchie
Marshal
Posts: 56522
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean, apart from the unbalanced brackets?

Why don't you try it out with something simpler.
Earlier, you wrote:database.setMaxConnectionsPerPartition(String.valueOf(dbPoolElement.getAttribute("ConPoolmaxConnections"));
Let's cut that down to size.
database.setMaxConnectionsPerPartition(String.valueOf(dbPoolElement.getAttribute("ConPoolmaxConnections")));
String.valueOf(dbPoolElement.getAttribute("ConPoolmaxConnections"))

Now, you can't simply print that sort of thing because you can't tell from the output whether it is an int or a String, so try this:-I think you can cast a primitive to Object; it will undergo boxing conversion. Simplified version:-
 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You want to use Integer.valueOf, not String.valueOf.

ETA: GAH! Completely misread the OP...ignore my dimness, which I shall leave here anyway for posterity...
 
Campbell Ritchie
Marshal
Posts: 56522
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I think OP wanted a String, so Integer.valueOf would give an inappropriate type.
Why on earth you have a database which uses a S‍tring to set a number, now that's a different question.
 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Welcome to the Ranch

I think OP wanted a String, so Integer.valueOf would give an inappropriate type.
Why on earth you have a database which uses a S‍tring to set a number, now that's a different question.


Yep, just caught that myself when I saw your long explanation...made me think one of us was reading things wrong, and it was probably me.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!