Results 1 to 2 of 2
- 02-16-2010, 05:41 PM #1
Member
- Join Date
- Jan 2010
- Posts
- 81
- Rep Power
- 0
Is it OK to do this... (converting int to string)
Is it OK to do this...
I'm just using that as an example, in my code I'm using it like this...Java Code:int x = 7; String string = ""+x;
Cost is an integer in my code, but I need to display it as a string to get it to work in a JLabel. I know there's another way to convert String to int, but this seems like a shortcut to me. Will this create any problems/issues down the road?Java Code:activationCost.setText(""+masterArray[masterCardID].getCost())
- 02-16-2010, 05:51 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,392
- Blog Entries
- 7
- Rep Power
- 17
There are no repercussions but it's not the most efficient way of converting an int to a String, i.e. the compiler helps you but it generates code like this:
The String class itself has better alternatives for it (although they are a bit longer source code wise speaking):Java Code:// String String= ""+x; String string= new StringBuilder("").append(x).toString();
kind regards,Java Code:String string= String.valueOf(x);
Jos
Similar Threads
-
Converting a String into a array.
By taraxgoesxboom in forum New To JavaReplies: 12Last Post: 02-22-2009, 05:29 AM -
NullPointerException converting String to double
By infaddict in forum New To JavaReplies: 3Last Post: 07-19-2008, 06:01 PM -
Converting object to string
By Preethi in forum New To JavaReplies: 4Last Post: 06-14-2008, 03:29 AM -
Converting String to Double
By srini in forum New To JavaReplies: 1Last Post: 12-24-2007, 08:03 PM -
Converting Epoch to string Date
By amyedwards in forum New To JavaReplies: 3Last Post: 12-14-2007, 10:33 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks