Note that there are some explanatory texts on larger screens.

plurals
  1. POVectors in Java, how to return multiple vectors in an object
    primarykey
    data
    text
    <p>I'm working on a java program, and I have several vectors defined and filled (from a file) inside a method. I need to return the contents of all the vectors from the method. I have heard you can put them all in one object to return them. Is that possible, and if so, how? If not, do you have any possible solutions for me? Thanks in advance for your help! </p> <p>Here is a code snippet:</p> <pre><code>Object getInventory() { Vector&lt;String&gt; itemID=new Vector&lt;String&gt;(); Vector&lt;String&gt; itemName=new Vector&lt;String&gt;(); Vector&lt;Integer&gt; pOrdered=new Vector&lt;Integer&gt;(); Vector&lt;Integer&gt; pInStore=new Vector&lt;Integer&gt;(); Vector&lt;Integer&gt; pSold=new Vector&lt;Integer&gt;(); Vector&lt;Double&gt; manufPrice=new Vector&lt;Double&gt;(); Vector&lt;Double&gt; sellingPrice=new Vector&lt;Double&gt;(); Object inventoryItem=new Object(); //object to store vectors in try { Scanner infile= new Scanner(new FileReader("Ch10Ex16Data.txt")); int i=0; while (infile.hasNext()) { itemID.addElement(infile.next()); itemName.addElement(infile.next()+infile.nextLine()); pOrdered.addElement(infile.nextInt()); pInStore.addElement(pOrdered.elementAt(i)); pSold.addElement(0); manufPrice.addElement(infile.nextDouble()); sellingPrice.addElement(infile.nextDouble()); i++; } infile.close(); System.out.println(itemID); System.out.println(itemName); System.out.println(pOrdered); System.out.println(pInStore); System.out.println(pSold); System.out.println(manufPrice); System.out.println(sellingPrice); } catch (Exception f) { System.out.print(f); } return inventoryItem; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload