Results 1 to 9 of 9
- 04-24-2010, 03:58 AM #1
Member
- Join Date
- Apr 2010
- Posts
- 19
- Rep Power
- 0
int[] with multi-digit values: toString()
How would you put
int[] intArray={1342,5523,7662,1242,...};
into a string such that
String arrayConverted="1342552376621242...";
--------------------------------------------------------------------------
Also, if I am using a Swing GUI and I want to make a textArea show a certain String, if I say
exampleTextArea.setText(String s);
is there a way I can get it to display the TEXT FROM THE STRING instead of the memory location of the string?:confused:
-
To convert the array to String, you can use String.valueOf(...) to convert each int to a String and either concatenate a single String or use a StringBuilder to append each new String.
As for displaying a String into a JTextArea, simply calling setText should be all you need to do. If you're getting something else, it may be that you're trying to add a String array or other non-String reference variable to the JTextArea.
- 04-24-2010, 05:14 AM #3
Member
- Join Date
- Apr 2010
- Posts
- 19
- Rep Power
- 0
what is String Builder?
-
It's actually StringBuilder, and it's a class that allows you to more efficiently concatenate Strings without creating any more objects than are needed. This can get real important if you have to do a lot of String concatenation very fast. Check out the API for more details.
- 04-24-2010, 02:47 PM #5
Member
- Join Date
- Apr 2010
- Posts
- 19
- Rep Power
- 0
I tried using the .valueOf thing, and it said something about class "value" being different from class "int".
Also, it turns out that every time I envoke the .toString() method, thats when it suddenly turns into a memory location instead of the intended string.Last edited by soccermiles; 04-24-2010 at 02:48 PM. Reason: more questions
-
- 04-25-2010, 03:33 PM #7
Member
- Join Date
- Apr 2010
- Posts
- 19
- Rep Power
- 0
I solved my problem using the StringBuilder object. Thank you very much for your help.
STRINGBUILDERS IS AWSOME!! BLAARRRGH!!! xDLast edited by soccermiles; 04-25-2010 at 03:36 PM. Reason: bad vocab
- 04-25-2010, 05:48 PM #8
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
I'll just point out that I've never used StringBuilder in my life :P
Works just fine :DJava Code:String s=""; //integers is an int[] for(int add:integers){ s+=add; } return s;If the above doesn't make sense to you, ignore it, but remember it - might be useful!
And if you just randomly taught yourself to program, well... you're just like me!
- 04-27-2010, 01:30 PM #9
Member
- Join Date
- Apr 2010
- Posts
- 19
- Rep Power
- 0
Similar Threads
-
adding values from file to multi-dimensional ArrayList
By sebo in forum New To JavaReplies: 7Last Post: 09-26-2011, 11:29 PM -
digit spacing
By puk284 in forum New To JavaReplies: 3Last Post: 06-09-2009, 02:49 PM -
Locating a digit within a string
By ScentOfAWookie in forum New To JavaReplies: 8Last Post: 03-27-2009, 05:23 PM -
Java newb Q: 8-digit id
By 1111FM in forum New To JavaReplies: 2Last Post: 09-29-2008, 02:37 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks