Results 1 to 3 of 3

Thread: StringArray questions

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2005
    Posts
    27

    StringArray questions

    Hello i need help with removing string. can someone please help me with my code.

    ------
    <code>
    public static StringArraySeq concatenation(StringArraySeq s1,StringArraySeq s2){

    //StringArraySeq s1=new StringArraySeq();
    //StringArraySeq s2=new StringArraySeq();
    StringArraySeq longStringArraySeq = new StringArraySeq(s1.size()+s2.size());
    //StringArraySeq longStringArraySeq = new StringArraySeq(100);
    System.arraycopy(s1.data,0,longStringArraySeq.data,0,s1.size());
    System.arraycopy(s2.data,0,longStringArraySeq.data,s1.size(),s2.size());
    longStringArraySeq.manyItems = s1.size() + s2.size();
    longStringArraySeq.currentIndex = longStringArraySeq.manyItems;

    return longStringArraySeq;


    }

    /**
    * Check if all the capacity has been consumed.
    * @return
    * boolean:
    * true (if no space left) or false (if space is available)
    */
    public boolean data1(){
    return (manyItems == getCapacity() );
    }


    public boolean isEmpty(){
    return (manyItems == 0);
    }

    /**
    * Return a String displaying items in the sequence
    * @return
    * String: shows the elements in sequence in set format.
    */
    public String toString(){

    String sa = "";
    //System.out.println( "Number.length = " + sa.length );
    //System.out.println();

    for (int i=0; i<manyItems; i++){
    sa = sa + "\n" + data[i];
    }
    return sa;

    }

    public String getString(String[] arg){

    return "";
    //return ;

    }


    /**
    * Print out a set representation of the sequence
    */
    public void print(){
    System.out.println(this);
    }

    public void addAfter(String element){
    if( isEmpty() ){
    data[0] = element;
    currentIndex = 0;


    }
    // make sure there's enough room
    else {
    if( data1() ) ensureCapacity();
    // increment currentIndex, and then put element
    // at currentIndex
    ++currentIndex;
    for( int i = manyItems; i > currentIndex; i-- ){
    data[i] = data[i-1];
    }
    data[currentIndex] = element;
    }
    ++manyItems;
    //--manyItems;
    }





    public boolean removeCurrent(){
    if( isEmpty())
    return false;
    else {
    if( manyItems == currentIndex + 1){
    --manyItems; // if pointing at last element in data.
    --currentIndex;
    }
    else {
    for( int i = currentIndex; i < manyItems; i++ )
    data[i] = data[i+1];
    --manyItems;
    //--currentIndex;
    }
    }
    return true;
    }



    public static void main (String [ ] args) {
    System.out.println("..:: Welcome ::..");
    System.out.println();

    // double [] d={12.4, 16.9,7.3,4.8};
    StringArraySeq sa=new StringArraySeq();

    sa.addAfter("first");
    sa.addAfter("second");
    sa.addAfter("third");
    // s.addBefore (11.5);
    //sa.toString();
    System.out.println(sa);
    //sa.toString();

    System.out.println();
    System.out.println();
    StringArraySeq s1=new StringArraySeq();
    s1.addAfter("first");
    s1.addAfter("second");
    StringArraySeq s2=new StringArraySeq();
    s2.addAfter("third");
    s2.addAfter("fourth");
    StringArraySeq bigS = StringArraySeq.concatenation(s1,s2);
    System.out.println(bigS.toString());
    bigS.removeCurrent("third");

    }</code>

    bigS.removeCurrent("third"); seem not working right.
    Last edited by indianj; Sep 30th, 2006 at 08:50 AM.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: StringArray questions

    You need to use code tags.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: StringArray questions

    What's "StringArraySeq" ?
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width