-2

The following line will working perfectly fine because I manually input the "new item(1,2,3)" into the item array?

But what i'm trying to do here is loop through a file and push "new item(1,2,3)" dynamically into "Lines[] item"

Which I currently got no idea how to go about pushing it in. THe following image is what happens when i do ** item.(Function)** enter image description here Any advice?

 Lines[] item
         = {new item(0, 2, 1),
            new item(0, 3, 4),
            new item(0, 4, 2),
           };

    Test test = new Test(item);
     // Test is a java file which will accept this
     public Test(List<Lines> item) {
        this.edges = edges;
      }
CodeGuru
  • 3,645
  • 14
  • 55
  • 99
  • Possible duplicate of [Converting array to list in Java](http://stackoverflow.com/questions/2607289/converting-array-to-list-in-java) – px5x2 Nov 05 '15 at 06:57
  • @px5x2 YOu mean i should push "new item(0, 3, 4) " into a array? – CodeGuru Nov 05 '15 at 07:00
  • 2
    its not really clear what you are trying to do here, you want to create an array dynamically ? – QuakeCore Nov 05 '15 at 07:00

2 Answers2

1
//Read data from some excel file using poi / jxl

String inputArray = td.getDataFromExcel().get(index);

//Read the array
List<String> items = Arrays.asList(inputArray.split("\\s*,\\s*"));

for (int i = 0; i < items.size(); i++) {
    // perform the operation of your choice
}
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Diptman
  • 374
  • 3
  • 14
1

If you change your array into a list you will be able to "push" an item into it. You can do this by changing "Lines[] item" into "List<Lines> item". Then you will be able to call the Add method on the list passing the item you want to "push" into item.

NecroTheif
  • 284
  • 1
  • 2
  • 12