Array to nice table presentation

Discussion in 'Java' started by lounger, Apr 14, 2004.

  1. lounger

    lounger Guest

    Hello all, I am somewhat of a newbiew but learn real fast.

    I have a Sorted Map and want to parse out the contents into a nice
    viewable table. My first thought was to create an HTML doc and display
    it in a JEditorPane.

    I can't, for the life of me, figure out how to get started. I am able
    to parse out the contents but am stuck there.

    I am open to any suggestions. But would prefer something not to
    complicated and not to have to save a file to the file system.

    Thanks a lot.
     
    lounger, Apr 14, 2004
    #1
    1. Advertising

  2. lounger

    John Guest

    lounger wrote:
    > Hello all, I am somewhat of a newbiew but learn real fast.
    >
    > I have a Sorted Map and want to parse out the contents into a nice
    > viewable table. My first thought was to create an HTML doc and display
    > it in a JEditorPane.
    >
    > I can't, for the life of me, figure out how to get started. I am able
    > to parse out the contents but am stuck there.
    >
    > I am open to any suggestions. But would prefer something not to
    > complicated and not to have to save a file to the file system.
    >
    > Thanks a lot.
    >

    Once you have parsed it what data structure is it in? Post it. All you
    have to do is restructure the data into a 2D array and then use it to
    spew out a great big string with a few <table><tr><td> type tags thrown
    in for good measure.

    john
     
    John, Apr 14, 2004
    #2
    1. Advertising

  3. lounger

    lounger Guest

    John wrote:

    > lounger wrote:
    >
    >> Hello all, I am somewhat of a newbiew but learn real fast.
    >>
    >> I have a Sorted Map and want to parse out the contents into a nice
    >> viewable table. My first thought was to create an HTML doc and display
    >> it in a JEditorPane.
    >>
    >> I can't, for the life of me, figure out how to get started. I am able
    >> to parse out the contents but am stuck there.
    >>
    >> I am open to any suggestions. But would prefer something not to
    >> complicated and not to have to save a file to the file system.
    >>
    >> Thanks a lot.
    >>

    > Once you have parsed it what data structure is it in? Post it. All you
    > have to do is restructure the data into a 2D array and then use it to
    > spew out a great big string with a few <table><tr><td> type tags
    > thrown in for good measure.
    >
    > john


    That makes sense. How do I get it into the JEditorPane?
    public JEditorPane drawDoc(String type) throws IOException{
    Set entrySet;
    compPane = null;
    compPane = new JEditorPane();
    compPane.setContentType("text/html");

    if (type.equals("Nets")) {
    entrySet = NetMap.getNets().entrySet();
    for (Iterator it = entrySet.iterator(); it.hasNext(); ) {
    Map.Entry entry = (Map.Entry)it.next();
    Net net = ((Net)entry.getValue());
    //These are the column entries
    netName = net.toString()
    isCrit = net.isBCrit();
    ...
    }
    }
    }
     
    lounger, Apr 14, 2004
    #3
  4. lounger

    John Guest

    lounger wrote:

    > John wrote:
    >
    >> lounger wrote:
    >>
    >>> Hello all, I am somewhat of a newbiew but learn real fast.
    >>>
    >>> I have a Sorted Map and want to parse out the contents into a nice
    >>> viewable table. My first thought was to create an HTML doc and display
    >>> it in a JEditorPane.
    >>>
    >>> I can't, for the life of me, figure out how to get started. I am able
    >>> to parse out the contents but am stuck there.
    >>>
    >>> I am open to any suggestions. But would prefer something not to
    >>> complicated and not to have to save a file to the file system.
    >>>
    >>> Thanks a lot.
    >>>

    >> Once you have parsed it what data structure is it in? Post it. All you
    >> have to do is restructure the data into a 2D array and then use it to
    >> spew out a great big string with a few <table><tr><td> type tags
    >> thrown in for good measure.
    >>
    >> john

    >
    >
    > That makes sense. How do I get it into the JEditorPane?
    > public JEditorPane drawDoc(String type) throws IOException{
    > Set entrySet; compPane = null;
    > compPane = new JEditorPane();
    > compPane.setContentType("text/html");
    >
    > if (type.equals("Nets")) {
    > entrySet = NetMap.getNets().entrySet();
    > for (Iterator it = entrySet.iterator(); it.hasNext(); ) {
    > Map.Entry entry = (Map.Entry)it.next();
    > Net net = ((Net)entry.getValue());
    > //These are the column entries
    > netName = net.toString()
    > isCrit = net.isBCrit();
    > ...
    > } }
    > }
    >

    Putting it into the JEditorPane is the straightforward bit.

    (JEditorPane myPane is initialised elsewhere)
    (mySortedMap is an entity object of your own creation.)

    String tableString = mySortedMap.getTableHTML();
    myPane.setText(tableString);

    (IS EQUIVALENT TO)

    myPane.setText(mySortedMap.getTableHTML()); //looks a bit neater

    John
     
    John, Apr 14, 2004
    #4
  5. lounger

    lounger Guest

    John wrote:

    > lounger wrote:
    >
    >> John wrote:
    >>
    >>> lounger wrote:
    >>>
    >>>> Hello all, I am somewhat of a newbiew but learn real fast.
    >>>>
    >>>> I have a Sorted Map and want to parse out the contents into a nice
    >>>> viewable table. My first thought was to create an HTML doc and
    >>>> display
    >>>> it in a JEditorPane.
    >>>>
    >>>> I can't, for the life of me, figure out how to get started. I am able
    >>>> to parse out the contents but am stuck there.
    >>>>
    >>>> I am open to any suggestions. But would prefer something not to
    >>>> complicated and not to have to save a file to the file system.
    >>>>
    >>>> Thanks a lot.
    >>>>
    >>> Once you have parsed it what data structure is it in? Post it. All
    >>> you have to do is restructure the data into a 2D array and then use
    >>> it to spew out a great big string with a few <table><tr><td> type
    >>> tags thrown in for good measure.
    >>>
    >>> john

    >>
    >>
    >>
    >> That makes sense. How do I get it into the JEditorPane?
    >> public JEditorPane drawDoc(String type) throws
    >> IOException{ Set entrySet; compPane = null;
    >> compPane = new JEditorPane();
    >> compPane.setContentType("text/html");
    >>
    >> if (type.equals("Nets")) {
    >> entrySet = NetMap.getNets().entrySet();
    >> for (Iterator it = entrySet.iterator(); it.hasNext(); ) {
    >> Map.Entry entry = (Map.Entry)it.next();
    >> Net net = ((Net)entry.getValue());
    >> //These are the column entries
    >> netName = net.toString()
    >> isCrit = net.isBCrit();
    >> ...
    >> } }
    >> }
    >>

    > Putting it into the JEditorPane is the straightforward bit.
    >
    > (JEditorPane myPane is initialised elsewhere)
    > (mySortedMap is an entity object of your own creation.)
    >
    > String tableString = mySortedMap.getTableHTML();
    > myPane.setText(tableString);
    >
    > (IS EQUIVALENT TO)
    >
    > myPane.setText(mySortedMap.getTableHTML()); //looks a bit neater
    >
    > John
    >
    >
    >

    I almost get it. Is mySortedMap the same as 'entrySet', or am I
    creating a new Sorted Map with the column values in it?
     
    lounger, Apr 14, 2004
    #5
  6. lounger

    lounger Guest

    John wrote:

    > lounger wrote:
    >
    >> John wrote:
    >>
    >>> lounger wrote:
    >>>
    >>>> Hello all, I am somewhat of a newbiew but learn real fast.
    >>>>
    >>>> I have a Sorted Map and want to parse out the contents into a nice
    >>>> viewable table. My first thought was to create an HTML doc and
    >>>> display
    >>>> it in a JEditorPane.
    >>>>
    >>>> I can't, for the life of me, figure out how to get started. I am able
    >>>> to parse out the contents but am stuck there.
    >>>>
    >>>> I am open to any suggestions. But would prefer something not to
    >>>> complicated and not to have to save a file to the file system.
    >>>>
    >>>> Thanks a lot.
    >>>>
    >>> Once you have parsed it what data structure is it in? Post it. All
    >>> you have to do is restructure the data into a 2D array and then use
    >>> it to spew out a great big string with a few <table><tr><td> type
    >>> tags thrown in for good measure.
    >>>
    >>> john

    >>
    >>
    >>
    >> That makes sense. How do I get it into the JEditorPane?
    >> public JEditorPane drawDoc(String type) throws
    >> IOException{ Set entrySet; compPane = null;
    >> compPane = new JEditorPane();
    >> compPane.setContentType("text/html");
    >>
    >> if (type.equals("Nets")) {
    >> entrySet = NetMap.getNets().entrySet();
    >> for (Iterator it = entrySet.iterator(); it.hasNext(); ) {
    >> Map.Entry entry = (Map.Entry)it.next();
    >> Net net = ((Net)entry.getValue());
    >> //These are the column entries
    >> netName = net.toString()
    >> isCrit = net.isBCrit();
    >> ...
    >> } }
    >> }
    >>

    > Putting it into the JEditorPane is the straightforward bit.
    >
    > (JEditorPane myPane is initialised elsewhere)
    > (mySortedMap is an entity object of your own creation.)
    >
    > String tableString = mySortedMap.getTableHTML();
    > myPane.setText(tableString);
    >
    > (IS EQUIVALENT TO)
    >
    > myPane.setText(mySortedMap.getTableHTML()); //looks a bit neater
    >
    > John
    >
    >
    >

    I almost get it. Is mySortedMap the same as 'entrySet', or am I
    creating a new Sorted Map with the column values in it?

    Thank you so much for your patients!

    This is what I have now:

    if (type.equals("Nets")) {
    entrySet = NetMap.getNets().entrySet();
    for (Iterator it = entrySet.iterator(); it.hasNext(); ) {
    Map.Entry entry = (Map.Entry)it.next();
    Net net = ((Net)entry.getValue());
    netString = net.toString()
    +" - "
    + net.isBCrit()
    +" - "
    + net.getDiffMate()
    +" - "
    + net.isBClk()
    +" - "
    + net.isBBus()
    +" - "
    + net.isBPwr()
    +" - "
    + net.isBGnd()
    +" - "
    + net.isBSingle()
    +" - "
    + net.isBDiff()
    +" - "
    + net.isTagged()
    +" - "
    + net.getId()
    + newLine
    ;
    System.out.println(netString);
    }
     
    lounger, Apr 14, 2004
    #6
  7. lounger

    John Guest

    lounger wrote:
    > John wrote:
    >
    >> lounger wrote:
    >>
    >>> John wrote:
    >>>
    >>>> lounger wrote:
    >>>>
    >>>>> Hello all, I am somewhat of a newbiew but learn real fast.
    >>>>>
    >>>>> I have a Sorted Map and want to parse out the contents into a nice
    >>>>> viewable table. My first thought was to create an HTML doc and
    >>>>> display
    >>>>> it in a JEditorPane.
    >>>>>
    >>>>> I can't, for the life of me, figure out how to get started. I am able
    >>>>> to parse out the contents but am stuck there.
    >>>>>
    >>>>> I am open to any suggestions. But would prefer something not to
    >>>>> complicated and not to have to save a file to the file system.
    >>>>>
    >>>>> Thanks a lot.
    >>>>>
    >>>> Once you have parsed it what data structure is it in? Post it. All
    >>>> you have to do is restructure the data into a 2D array and then use
    >>>> it to spew out a great big string with a few <table><tr><td> type
    >>>> tags thrown in for good measure.
    >>>>
    >>>> john
    >>>
    >>>
    >>>
    >>>
    >>> That makes sense. How do I get it into the JEditorPane?
    >>> public JEditorPane drawDoc(String type) throws
    >>> IOException{ Set entrySet; compPane = null;
    >>> compPane = new JEditorPane();
    >>> compPane.setContentType("text/html");
    >>>
    >>> if (type.equals("Nets")) {
    >>> entrySet = NetMap.getNets().entrySet();
    >>> for (Iterator it = entrySet.iterator(); it.hasNext(); ) {
    >>> Map.Entry entry = (Map.Entry)it.next();
    >>> Net net = ((Net)entry.getValue());
    >>> //These are the column entries
    >>> netName = net.toString()
    >>> isCrit = net.isBCrit();
    >>> ...
    >>> } }
    >>> }
    >>>

    >> Putting it into the JEditorPane is the straightforward bit.
    >>
    >> (JEditorPane myPane is initialised elsewhere)
    >> (mySortedMap is an entity object of your own creation.)
    >>
    >> String tableString = mySortedMap.getTableHTML();
    >> myPane.setText(tableString);
    >>
    >> (IS EQUIVALENT TO)
    >>
    >> myPane.setText(mySortedMap.getTableHTML()); //looks a bit neater
    >>
    >> John
    >>
    >>
    >>

    > I almost get it. Is mySortedMap the same as 'entrySet', or am I
    > creating a new Sorted Map with the column values in it?
    >
    > Thank you so much for your patients!
    >
    > This is what I have now:
    >
    > if (type.equals("Nets")) {
    > entrySet = NetMap.getNets().entrySet();
    > for (Iterator it = entrySet.iterator(); it.hasNext(); ) {
    > Map.Entry entry = (Map.Entry)it.next();
    > Net net = ((Net)entry.getValue());
    > netString = net.toString()
    > +" - "
    > + net.isBCrit()
    > +" - "
    > + net.getDiffMate()
    > +" - "
    > + net.isBClk()
    > +" - "
    > + net.isBBus()
    > +" - "
    > + net.isBPwr()
    > +" - "
    > + net.isBGnd()
    > +" - "
    > + net.isBSingle()
    > +" - "
    > + net.isBDiff()
    > +" - "
    > + net.isTagged()
    > +" - "
    > + net.getId()
    > + newLine
    > ;
    > System.out.println(netString);
    > }
    >


    Forget the "mySortedMap" thing for now. I assume that each time you go
    round the for loop and print netString you are printing the data for one
    row. What you need to do is insert HTML instead of all the hyphens.

    A table looks like this in HTML (2 rows and 5 cols)

    <table>
    <tr>
    <td>data</td>
    <td>data</td>
    <td>data</td>
    <td>data</td>
    <td>data</td>
    </tr>
    <tr>
    <td>data</td>
    <td>data</td>
    <td>data</td>
    <td>data</td>
    <td>data</td>
    </tr>
    </table>

    so for each row you want:

    <td>data</td>
    <td>data</td>
    <td>data</td>
    <td>data</td>
    <td>data</td>

    where data is just whatever you are displaying.

    Then all you need to do is create another string to start with "<table>"
    and add netString after each trip around the for loop. Once you have
    finished the for loop add </table>.

    Finally put this huge string with all the table data into the
    JEditorPane using setText().

    Hey presto.

    John
     
    John, Apr 14, 2004
    #7
  8. lounger

    GaryM Guest

    lounger <> wrote in
    news:22afc.7644$:

    > Hello all, I am somewhat of a newbiew but learn real fast.
    >
    > I have a Sorted Map and want to parse out the contents into a nice
    > viewable table. My first thought was to create an HTML doc and
    > display it in a JEditorPane.
    >
    > I can't, for the life of me, figure out how to get started. I am
    > able to parse out the contents but am stuck there.
    >
    > I am open to any suggestions. But would prefer something not to
    > complicated and not to have to save a file to the file system.
    >
    > Thanks a lot.
    >



    If you are open to open source, check out display tag library for a
    sweet set of tools which should cover all html table needs.

    Project page is:

    http://sourceforge.net/projects/displaytag/

    Home page is

    http://displaytag.sourceforge.net/
     
    GaryM, Apr 14, 2004
    #8
  9. lounger

    lounger Guest

    John wrote:

    > lounger wrote:
    >
    >> John wrote:
    >>
    >>> lounger wrote:
    >>>
    >>>> John wrote:
    >>>>
    >>>>> lounger wrote:
    >>>>>
    >>>>>> Hello all, I am somewhat of a newbiew but learn real fast.
    >>>>>>
    >>>>>> I have a Sorted Map and want to parse out the contents into a nice
    >>>>>> viewable table. My first thought was to create an HTML doc and
    >>>>>> display
    >>>>>> it in a JEditorPane.
    >>>>>>
    >>>>>> I can't, for the life of me, figure out how to get started. I am
    >>>>>> able
    >>>>>> to parse out the contents but am stuck there.
    >>>>>>
    >>>>>> I am open to any suggestions. But would prefer something not to
    >>>>>> complicated and not to have to save a file to the file system.
    >>>>>>
    >>>>>> Thanks a lot.
    >>>>>>
    >>>>> Once you have parsed it what data structure is it in? Post it. All
    >>>>> you have to do is restructure the data into a 2D array and then
    >>>>> use it to spew out a great big string with a few <table><tr><td>
    >>>>> type tags thrown in for good measure.
    >>>>>
    >>>>> john
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>> That makes sense. How do I get it into the JEditorPane?
    >>>> public JEditorPane drawDoc(String type) throws
    >>>> IOException{ Set entrySet; compPane = null;
    >>>> compPane = new JEditorPane();
    >>>> compPane.setContentType("text/html");
    >>>>
    >>>> if (type.equals("Nets")) {
    >>>> entrySet = NetMap.getNets().entrySet();
    >>>> for (Iterator it = entrySet.iterator(); it.hasNext(); ) {
    >>>> Map.Entry entry = (Map.Entry)it.next();
    >>>> Net net = ((Net)entry.getValue());
    >>>> //These are the column entries
    >>>> netName = net.toString()
    >>>> isCrit = net.isBCrit();
    >>>> ...
    >>>> } }
    >>>> }
    >>>>
    >>> Putting it into the JEditorPane is the straightforward bit.
    >>>
    >>> (JEditorPane myPane is initialised elsewhere)
    >>> (mySortedMap is an entity object of your own creation.)
    >>>
    >>> String tableString = mySortedMap.getTableHTML();
    >>> myPane.setText(tableString);
    >>>
    >>> (IS EQUIVALENT TO)
    >>>
    >>> myPane.setText(mySortedMap.getTableHTML()); //looks a bit neater
    >>>
    >>> John
    >>>
    >>>
    >>>

    >> I almost get it. Is mySortedMap the same as 'entrySet', or am I
    >> creating a new Sorted Map with the column values in it?
    >>
    >> Thank you so much for your patients!
    >>
    >> This is what I have now:
    >>
    >> if (type.equals("Nets")) { entrySet =
    >> NetMap.getNets().entrySet();
    >> for (Iterator it = entrySet.iterator(); it.hasNext(); ) {
    >> Map.Entry entry = (Map.Entry)it.next();
    >> Net net = ((Net)entry.getValue());
    >> netString = net.toString()
    >> +" - "
    >> + net.isBCrit()
    >> +" - "
    >> + net.getDiffMate()
    >> +" - "
    >> + net.isBClk()
    >> +" - "
    >> + net.isBBus()
    >> +" - "
    >> + net.isBPwr()
    >> +" - "
    >> + net.isBGnd()
    >> +" - "
    >> + net.isBSingle()
    >> +" - "
    >> + net.isBDiff()
    >> +" - "
    >> + net.isTagged()
    >> +" - "
    >> + net.getId()
    >> + newLine
    >> ;
    >> System.out.println(netString);
    >> }
    >>

    >
    > Forget the "mySortedMap" thing for now. I assume that each time you
    > go round the for loop and print netString you are printing the data
    > for one row. What you need to do is insert HTML instead of all the
    > hyphens.
    >
    > A table looks like this in HTML (2 rows and 5 cols)
    >
    > <table>
    > <tr>
    > <td>data</td>
    > <td>data</td>
    > <td>data</td>
    > <td>data</td>
    > <td>data</td>
    > </tr>
    > <tr>
    > <td>data</td>
    > <td>data</td>
    > <td>data</td>
    > <td>data</td>
    > <td>data</td>
    > </tr>
    > </table>
    >
    > so for each row you want:
    >
    > <td>data</td>
    > <td>data</td>
    > <td>data</td>
    > <td>data</td>
    > <td>data</td>
    >
    > where data is just whatever you are displaying.
    >
    > Then all you need to do is create another string to start with
    > "<table>" and add netString after each trip around the for loop. Once
    > you have finished the for loop add </table>.
    >
    > Finally put this huge string with all the table data into the
    > JEditorPane using setText().
    >
    > Hey presto.
    >
    > John


    That's exactly what I just did ( I guess I got it after all). Thanks.
    However, it is extremely slow. Is there a better way?
     
    lounger, Apr 14, 2004
    #9
  10. lounger wrote:

    > That's exactly what I just did ( I guess I got it after all). Thanks.
    > However, it is extremely slow. Is there a better way?


    What part is extremely slow? Setting the content of the JTextPane or
    creating the HTML String? If it is the latter, you that you are using a
    StringBuffer and not just appending to a String instead.

    --
    Kind regards,
    Christophe Vanfleteren
     
    Christophe Vanfleteren, Apr 14, 2004
    #10
  11. lounger

    Chris Smith Guest

    lounger wrote:
    > I have a Sorted Map and want to parse out the contents into a nice
    > viewable table. My first thought was to create an HTML doc and display
    > it in a JEditorPane.


    That's certainly doable, and you've got a good bit of advice on how to
    do it. If you're looking for other options, though, it wouldn't be too
    difficult to display the data in a JTable. The advantage is that the
    JTable would read data in the native form rather than building and
    parsing an intermediate file format, and that the data can be more
    immediately manipulated by the user (e.g., by selecting a set of cells
    and so forth) for further operations.

    To do this, look into implementing a TableModel by extending
    AbstractTableModel. You just need to provide methods to get the data at
    certain locations, and to report the total number of rows and columns.

    --
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
     
    Chris Smith, Apr 14, 2004
    #11
  12. lounger

    Roedy Green Guest

    On Wed, 14 Apr 2004 12:22:22 GMT, lounger <> wrote
    or quoted :

    >I have a Sorted Map and want to parse out the contents into a nice
    >viewable table. My first thought was to create an HTML doc and display
    >it in a JEditorPane.


    I suppose you could, but the code will run faster if you build a
    JTable.

    Google to find yourself some tutorials on setting them up. The
    trickiest thing about them is JTable is single thread. You must do
    everything on the Swing thread, perhaps using invokeLater.

    To get started see http://mindprod.com/jgloss/jtable.html

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Apr 15, 2004
    #12
  13. lounger

    Liz Guest

    "Roedy Green" <> wrote in message
    news:...
    > On Wed, 14 Apr 2004 12:22:22 GMT, lounger <> wrote
    > or quoted :
    >
    > >I have a Sorted Map and want to parse out the contents into a nice
    > >viewable table. My first thought was to create an HTML doc and display
    > >it in a JEditorPane.

    >
    > I suppose you could, but the code will run faster if you build a
    > JTable.
    >
    > Google to find yourself some tutorials on setting them up. The
    > trickiest thing about them is JTable is single thread. You must do
    > everything on the Swing thread, perhaps using invokeLater.
    >
    > To get started see http://mindprod.com/jgloss/jtable.html


    I got the sun SimpleTableDemo.java program from their web site
    and filled it with time zones using
    TimeZone.getTimeZone, and it looks real nice. Better than html I think.

    >
    > --
    > Canadian Mind Products, Roedy Green.
    > Coaching, problem solving, economical contract programming.
    > See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Liz, Apr 16, 2004
    #13
  14. lounger

    SPC Guest

    Christophe Vanfleteren <> wrote in message news:<6Idfc.71225$-ops.be>...
    > lounger wrote:
    >
    > > That's exactly what I just did ( I guess I got it after all). Thanks.
    > > However, it is extremely slow. Is there a better way?

    >
    > What part is extremely slow? Setting the content of the JTextPane or
    > creating the HTML String? If it is the latter, you that you are using a
    > StringBuffer and not just appending to a String instead.


    AFAIK as of JDK1.4.0 string appending automatically uses a
    stringbuffer, and there is no-longer a need to manually use a
    stringbuffer for simple 'one line' appends like:
    String s = "a" + c + "c"; // or similar

    Fine if you can be sure of your JDK.

    Regards

    Steve
     
    SPC, Apr 16, 2004
    #14
  15. SPC wrote:

    >> What part is extremely slow? Setting the content of the JTextPane or
    >> creating the HTML String? If it is the latter, you that you are using a
    >> StringBuffer and not just appending to a String instead.

    >
    > AFAIK as of JDK1.4.0 string appending automatically uses a
    > stringbuffer, and there is no-longer a need to manually use a
    > stringbuffer for simple 'one line' appends like:
    > String s = "a" + c + "c"; // or similar
    >
    > Fine if you can be sure of your JDK.


    Appending like this has always used a StringBuffer for these constructs
    IIRC.

    But it is very unprobable that the OP is using this kind of construct to
    generate an entire html table. He's probable appending to a String in a
    loop, and in those cases, you need to use the StringBuffer for sure.

    Consider

    String s = "<table>";
    for(int i=0;i<1000;i++) {
    s = s + "<tr><td>a";
    }

    vs

    StringBuffer sb = new StringBuffer(4000)
    for(int i=0;i<1000;i++) {
    a.append("<tr><td>")
    a.append("a");
    }



    --
    Kind regards,
    Christophe Vanfleteren
     
    Christophe Vanfleteren, Apr 16, 2004
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Williams
    Replies:
    2
    Views:
    1,171
    Jacob Yang [MSFT]
    Aug 12, 2003
  2. Rio
    Replies:
    4
    Views:
    1,241
  3. Gerrit Muller

    Nice presentation of Dana Moore on Oscon

    Gerrit Muller, Jul 11, 2003, in forum: Python
    Replies:
    4
    Views:
    382
    Edward K. Ream
    Jul 16, 2003
  4. Carramba

    printing nice table

    Carramba, Jun 11, 2007, in forum: C Programming
    Replies:
    2
    Views:
    331
    Christopher Benson-Manica
    Jun 11, 2007
  5. Max Williams
    Replies:
    12
    Views:
    243
    Clifford Heath
    Sep 13, 2009
Loading...

Share This Page