Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Large array's to Strings in Java

Options
  • 07-02-2007 2:37pm
    #1
    Registered Users Posts: 354 ✭✭


    Let me start by saying that I feel particularly dumb today so bear with me.

    My problem is to be the volume of data I'm working with.
    My data is contained in a text file arranged in 1000 rows of 2700 numbers.
    I was advised to convert this into an array to make it easier to access and doing that is trivial.
    The difficulty arises when I try to display the entire data in a TextArea. While creating the array is simple and quick, converting it into a single String is excrutiatingly slow. Unfortunatly I need to be able to display and operate on the data.
    Can any of you suggest either an alternative approach or any hints and tips to improve the execution?

    Thanks.


Comments

  • Registered Users Posts: 4,188 ✭✭✭pH


    Bunging 2,700 x 1,000 items into a huge string and then displaying that in a TextArea is indeed inefficient.

    Have you considered possibly using a TableModel and JTable to display it. This should be much better because you can implement the tablemodel interface and use this new object to wrap your large array.

    Implementing tablemodel for you will just mainly involve overriding getObject(row,col)
    getRowCount()
    getColumnCount()

    (plus a few other methods like addListener() ),

    but all the other methods you can just ignore as you are just displaying it. If you want to change the array behind the scenes and have the UI update you will need to understand and implement some sort of fireEvent code.

    Anyway it's quite simple, should be around 50 lines of code all told.


  • Registered Users Posts: 1,996 ✭✭✭lynchie


    Also if your doing loads of String concatenations i.e. s+=s1+s2+s3 your better off using a StringBuffer instead.


  • Closed Accounts Posts: 362 ✭✭information


    lynchie wrote:
    Also if your doing loads of String concatenations i.e. s+=s1+s2+s3 your better off using a StringBuffer instead.
    I'll see your StringBuffer and raise you StringBuilder.

    Assuming the data from the text file will not change, you can:

    a)
    You read the textfile into a string first.
    Then split the string into the array.
    You can use the original string in the textarea

    or

    b)
    Using your current operation and then
    Just reread the data fromthe file into a string, for displaying in the textarea.


Advertisement