Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
希望用Java编写代码以获取数组中所有项的详细信息(输入长度不同)_Java_Arrays_Arraylist_String Formatting - Fatal编程技术网

希望用Java编写代码以获取数组中所有项的详细信息(输入长度不同)

希望用Java编写代码以获取数组中所有项的详细信息(输入长度不同),java,arrays,arraylist,string-formatting,Java,Arrays,Arraylist,String Formatting,如果您正在寻找一种方法来检索ItemTest类的Rocket itemList[]的值,您可以在ItemTest类中为Rocket itemList[]编写一个getter,如下所示 //Class Item public class Item { } String A, B; int C, D; // Constructor public Item(String A, String B, int C, int D) { this.A = A; this.B = B t

如果您正在寻找一种方法来检索
ItemTest
类的
Rocket itemList[]
的值,您可以在
ItemTest
类中为
Rocket itemList[]
编写一个getter,如下所示

//Class Item
public class Item {

}

String A, B; 
    int C, D;

// Constructor


public Item(String A, String B, int C, int D) {

this.A = A;

this.B = B

this.C = C;

this.D = D

public String toFormattedString() {

        return String.format("%s %s %d %d", A, B, C, D);    

//Class ItemTest

public class ItemTest {

    Rocket itemList [];


public ItemTest() {

      itemList = new Item[5];
      doSampleItem();

itemList[0] = new Item("A”, "ABC DEF", 400, 35);

itemList[1] = new Item("aaaa”, "bbbbbbbbbb", 10, 1000);

itemList[2] = new Item("ccc ddddd”, "eeeee ffff jjjj", 66000, 888);

我必须显示数组的格式化输出。如果你看到的话,它接受任意长度的输入。所以我对如何让它工作感到困惑。我使用了normal For Loop和System.out.print,但这并不是为不同长度的输入字符串格式化输出。我没有在主要问题中添加此要求。不知道如何在我的主查询中编辑此内容:(我是新的
public Rocket getItemList() {
    return this.itemList;
}