user1835502
user1835502

Reputation: 7

String[] to indivdual strings

I don't really know how to word the question, because i dont really understand how to do it

I've got two '.java' files

createFile:

public void addRecords(String Package, String ClassName, String[] ListOfBoxes)
{
    format.format("%s", "package " + Package + ";"\n");
    format.format("%s", "@SideOnly(Side.CLIENT)\n");
    format.format("%s", "public class " + ClassName + " extends ModelBiped\n");
    format.format("%s", "{\n");
    format.format("%s", "    ModelRenderer " + ListOfBoxes + ";\n");
    format.format("%s", "}\n");

   }

code i'm trying to run

            createFile file = new createFile();
    file.openFile();
    String[] Boxes = {"test1", "test2", "test3"};
    file.addRecords("default", "ModelTest", Boxes);         
    file.closeFile();

this is the output:

package net.minecraft.client.model;
@SideOnly(Side.CLIENT)
public class ModelTest extends ModelBiped
{
    ModelRenderer [Ljava.lang.String;@3794d372;
}

this is what i want

package net.minecraft.client.model;
@SideOnly(Side.CLIENT)
public class ModelTest extends ModelBiped
{
    ModelRenderer test1;
    ModelRenderer test2;
    ModelRenderer test3;
}

this is probably very simple but i'm a noob at java

thanks in advance

Upvotes: 0

Views: 63

Answers (2)

Gijs Overvliet
Gijs Overvliet

Reputation: 2691

try this for createFile:

public void addRecords(String Package, String ClassName, String[] ListOfBoxes)
{
    format.format("%s", "package " + Package + ";"\n");
    format.format("%s", "@SideOnly(Side.CLIENT)\n");
    format.format("%s", "public class " + ClassName + " extends ModelBiped\n");
    format.format("%s", "{\n");
    for (String box : listOfBoxes)
    {
        format.format("%s", "    ModelRenderer " + box + ";\n");
    }
    format.format("%s", "}\n");

}

The difference is that this code renders each element in the array, while your code renders the entire array in one go.

Upvotes: 0

linski
linski

Reputation: 5094

You want the Arrays.deepToString method. Rewrite the corresponding line in your addRecords method like this:

format.format("%s", "    ModelRenderer " + Arrays.deepToString(ListOfBoxes) + ";\n");

Upvotes: 1

Related Questions