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

[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.

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

String generatedArray = " ";

for (int i=0;i<array.length;i++){
generatedArray = generatedArray + array[i];
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.