Results 1 to 6 of 6
- 11-01-2012, 02:14 PM #1
Member
- Join Date
- Sep 2012
- Posts
- 11
- Rep Power
- 0
Adding a Value to an Arraylist of String arrays.
Hello ,
i have made a try catch statement so the program wont crash if an index is empty when it tries to access it.
What i then want to do if there is a "catch", is to set that index with a value of my choice. So when later on it
is used in the program, it is atlest " ".
and then the error messageJava Code:try { special1 = bookInfoSplitList.get(0)[7]; } catch (Exception e) { special1 = " "; bookInfoSplitList.add(0)[7] = special1; }
Best RegardsXML Code:./Books.java:79: cannot find symbol symbol : method add(int) location: class java.util.ArrayList<java.lang.String[]> bookInfoSplitList.add(0)[7] = special1;
PLast edited by Problemer; 11-01-2012 at 02:22 PM.
- 11-01-2012, 02:22 PM #2
Re: Adding a Value to an Arraylist of String arrays.
You have an ArrayList of Strings. You're trying to add a single int to that ArrayList, and then for some reason you're trying to use an array index on that. None of that makes much sense. What exactly are you trying to do here?
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 11-01-2012, 02:45 PM #3
Member
- Join Date
- Sep 2012
- Posts
- 11
- Rep Power
- 0
Re: Adding a Value to an Arraylist of String arrays.
Sorry the variables are not delcared in the code here.
But we are not talking INT , its strings.
The arraylist is an arraylist where every index contains an array of strings. (arraylist)[stringarrays] , if for example position (0)[1] is empty when trying to write to a file the program will crash.
Thats why i am trying to check if there is an value in it before , if not write something to it.
- 11-01-2012, 02:45 PM #4
Re: Adding a Value to an Arraylist of String arrays.
With line 2, you are assigning special1 the value of the item at index 7 in the array at position 0 in bookInfoSplitList.
Assuming that you want to change the value of the item at index 7 in the array at position 0, you could create a String[] variable,
and set it's value to be the String[] at position 0 in bookInfoSplitList.
Once you have the String[], you can set the value at index 7 to be whatever you want it to be (looks like you want a single space).
Then you would simply set the value at index 0 of bookInfoSplitList to be equal to your new String[], essentially overriding what was there.
- 11-01-2012, 02:47 PM #5
Re: Adding a Value to an Arraylist of String arrays.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 11-01-2012, 02:50 PM #6
Member
- Join Date
- Sep 2012
- Posts
- 11
- Rep Power
- 0
Similar Threads
-
Converting Arraylist to String array
By ankit1801 in forum New To JavaReplies: 3Last Post: 03-23-2011, 10:07 AM -
Binary-algorithm -> Insert String to sorted String-ArrayList
By Muskar in forum Advanced JavaReplies: 12Last Post: 11-26-2010, 08:33 AM -
Test for all empty Strings in LinkedHashMap<String,ArrayList<String>
By albertkao in forum New To JavaReplies: 1Last Post: 11-04-2010, 06:53 PM -
Send and receieve ArrayList and String Array from server to client
By johnnyjohn2009 in forum NetworkingReplies: 2Last Post: 03-16-2010, 07:01 AM -
Putting a string into ArrayList<String>
By k4ff1n34dd1c7 in forum New To JavaReplies: 5Last Post: 03-23-2009, 05:10 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks