• Post Reply Bookmark Topic Watch Topic
  • New Topic

Copy array content to arraylist  RSS feed

 
Derek Smiths
Ranch Hand
Posts: 119
Eclipse IDE Mac VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a text file which contains to integer values I need to retrieve for each item (total of 56 items in the file). One is an item number, the other the weight ("Item: " + number + "Weight: " + weight). I am trying to build an array list that will add each set of data to it. I know that when I add the item array to the arraylist it is storing the array variable and not its contents, so is there a way to easily copy that data array to the array list?

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arrays themselves don't have a whole lot of interoperability, but you may want to check out the java.util.Arrays utility class.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where does the array come from; you appear to have a 2‑element array but you are not using it.
Go through your loop carefully and work out what you are adding to the List. I do not think you are adding what you think you are adding. What is br and what is sc? Are you using two different objects to read from the same file? I am sure that won't work.
 
Charles Sexton
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Arrays themselves don't have a whole lot of interoperability, but you may want to check out the java.util.Arrays utility class.


Just as Bear stated, check out the Arrays utility class. If you can't find it there try Arrays. in your IDE and look for a method in which converts it into a list.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!