Arrays

Reply

Join Date: Jun 2004
Posts: 609
Reputation: freesoft_2000 is an unknown quantity at this point 
Solved Threads: 7
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster

Arrays

 
0
  #1
Jun 17th, 2005
Hi everyone,


I am currently trying to add values to an element spec array dynamically.


This is what i am trying to do

  1.  
  2. SimpleAttributeSet start = new SimpleAttributeSet();
  3. start.addAttribute(AbstractDocument.ElementNameAttribute, "start");
  4.  
  5. SimpleAttributeSet end = new SimpleAttributeSet();
  6. end.addAttribute(AbstractDocument.ElementNameAttribute, "end");
  7.  
  8.  
  9. DefaultStyledDocument.ElementSpec esStart1 = new DefaultStyledDocument.ElementSpec(start, DefaultStyledDocument.ElementSpec.StartTagType);
  10. DefaultStyledDocument.ElementSpec esStart2 = new DefaultStyledDocument.ElementSpec(start, DefaultStyledDocument.ElementSpec.StartTagType);
  11. DefaultStyledDocument.ElementSpec esStart3 = new DefaultStyledDocument.ElementSpec(start, DefaultStyledDocument.ElementSpec.StartTagType);
  12.  
  13. DefaultStyledDocument.ElementSpec esEnd1 = new DefaultStyledDocument.ElementSpec(end, DefaultStyledDocument.ElementSpec.EndTagType);
  14. DefaultStyledDocument.ElementSpec esEnd2 = new DefaultStyledDocument.ElementSpec(end, DefaultStyledDocument.ElementSpec.EndTagType);
  15. DefaultStyledDocument.ElementSpec esEnd3 = new DefaultStyledDocument.ElementSpec(end, DefaultStyledDocument.ElementSpec.EndTagType);
  16.  
  17. DefaultStyledDocument.ElementSpec[] esArray = {
  18. esStart1,
  19. esEnd1,
  20. esStart2,
  21. esEnd2,
  22. esStart3,
  23. esEnd3};

The above code is trying to add some custom elements into the styyled document but the thing is that i do not know what amount of this element does the user require. For example if the user requires only one of this element then this is what i would add into the array

  1. DefaultStyledDocument.ElementSpec[] esArray = {
  2. esStart1,
  3. esEnd1}


if the user wants two types of this elements then i this is what i would add into the array

  1. DefaultStyledDocument.ElementSpec[] esArray = {
  2. esStart1,
  3. esEnd1,
  4. esStart2,
  5. esEnd2};

The thing is i would not be able to know whatever the fixed array size is but this array has to be of an exact size because it is an element that is being added to the styled document

What i want to able to do is to find a way in which i can add these elements to the styled document even after its array size has been declared thus expanding the array size and adding values to it.

Some examples or sample codings would really be helpful

I hope someone can help me with this problem

Thank You

Yours Sincerely

Richard West
Microsoft uses "One World, One Web, One Program" as a slogan.
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond

Tell me what type of software do you like and what would you pay for it

http://www.daniweb.com/techtalkforums/thread19660.html
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 121
Reputation: tonakai is an unknown quantity at this point 
Solved Threads: 11
tonakai's Avatar
tonakai tonakai is offline Offline
Junior Poster

Re: Arrays

 
0
  #2
Jun 17th, 2005
if you want to dynamic array, you need to use ArrayList, check the documentation for details....
Good news, everyone!
aykutsoysal.com
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Arrays

 
0
  #3
Jun 17th, 2005
There's really no other way than creating a new array each time.
  1. String[] original = new String[4];
  2. String[] temp = new String[words.length+1];
  3.  
  4. original = temp;

I'm sure a performance hit would come out of that.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Arrays

 
0
  #4
Jun 20th, 2005
If your inserting a lot, maybe a LinkedList would be better. Let us know what you come up with.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 609
Reputation: freesoft_2000 is an unknown quantity at this point 
Solved Threads: 7
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster

Re: Arrays

 
0
  #5
Jun 21st, 2005
Hi everyone,

I used the ArrayList, it worked perfectly for my uses

Thank You

Richard West
Microsoft uses "One World, One Web, One Program" as a slogan.
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond

Tell me what type of software do you like and what would you pay for it

http://www.daniweb.com/techtalkforums/thread19660.html
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC