Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: James Rivera   on Nov 14 In Java Category.

  
Question Answered By: Frank Butler   on Nov 14

Well, the problem is that you are passing an array  into a method
that only accepts a string  object. Another way to get desired
effect when you have an array of Strings and you want to pass it all
into a function that requires a String would be to loop through the
entire array. For example:

----
String finalText = "";

for (int i = 0; i < vArray.length; i++)
{
finalText += vArray[i] + " ";
}

finalText = finalText.trim();
jTextField2.setText(finalText);
----

This will create a String that contains all of the text from the
array and place it into the text field. If this was what you were
wanting to do, then I would suggest to do something like the
following:

----
public String funcaoDivideString(String vParametro)
{

String[] vArray = vParametro.split(".");

jTextField1.setText("value");
jTextField2.setText(vParametro);

return vParametro;
}
----


Also, I noticed that you are returning the same string that you are
passing in. Just to let you know, Java uses "pass-by-value" so the
String passed in cannot be modified and retain it's value once the
method is completed. Perahps you wanted to set "jTextField2" to ONE
of the values in the array? If this was the case then you would do
something like this:

----
jTextField2.setText(vArray[0]); //This will push in the first value.
----

or

----
jTextField2.setText(vArray[1]); //This will push in the second value.
----

or

----
jTextField2.setText(vArray[2]); //This will push in the third value.
----

I am not sure what exactly you wanted your function to do so I can't
give you any other example. I am guessing from the name of it, you
wanted to split the array for some reason?

Share: