0

Hi!

I am creating a desktop Java application using Netbeans. My task is to generate an array and than sort it (InsertSort, SelectSort, BubbleSort).

My question is how do I show the value of all elements from generated array into the textfield?


What i have tried to do is:

Random R = new Random();

String arrayLength = arrayLength_TF.getText(); 
String randomValue = randomValue_TF.getText(); 

int a = Integer.parseInt(arrayLength);
int b = Integer.parseInt(randomValue);

int []array = new int[a];

for (int i=0; i< array.length; i++){
array[i]= R.nextInt(b);
}


String generatedArray = array.toString();


generatedArray_TF.setText(generatedArray);

Instead of getting the elements value i get value like this in my TextField: [I@1ea5671

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by MrVladar
0

[I@1ea5671 is the result of calling toString() on an array - its the method inherited from Object that just gives the object type and address
The Arrays class has a toString method that you can use to get a quick text version of an int array. Details in the API.

0

Thanks, i think that i solved my problem with this:

String generatedArray = " ";

for (int i=0;i<array.length;i++){
generatedArray = generatedArray + array[i];
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.