Java Tutorial. Java String Operations. Java - Print String to Console. Java - Read String from Console. Java - Concatente two Strings. Connect and share knowledge within a single location that is structured and easy to search.
How are we doing? Please help us improve Stack Overflow. Take our short survey. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. How can I initialization String array set null in java? Asked 7 years, 7 months ago. Active 7 years, 7 months ago. Viewed 16k times. Problem: I am trying to read in a line of text from a text file and store the words into an array.
Right now the array size is hard-coded with an number of indexes for test purposes, but I want to make the array capable of reading in a text file of any size instead. You can use java. ArrayList which dynamically grows unlike an array with fixed size to store the string objects test file lines by replacing your array with the below code:. You need to use add string to add a line string and get index to retrieve the line string. You may want to give a try to ArrayList.
In Java normal arrays cannot be initialized without giving initial size and they cannot be expanded during run time. Whereas ArrayLists have resizable-array implementation of the List interface.
ArrayList also comes with number of useful builtin functions such as. On top of these you can always convert your ArrayList to simple array using ArrayList function toArray. Hope this answers your question.
I'll prepare some code and share with you to further explain things you can achieve using List interface. How are we doing? Please help us improve Stack Overflow. Take our short survey. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow.
0コメント