Results 1 to 11 of 11
  1. #1
    sara12345 is offline Member
    Join Date
    Dec 2009
    Posts
    59
    Rep Power
    0

    Default adding elemnts of two dimentional array into vector

    hello everyone
    I need to add elemnts of two dimentional array
    eg. (sub_string_testvec[u][x]) into vector (test_Pattern_after_filling)
    I mean I want to add element (sub_string_testvec[u][0]., sub_string_testvec[u][1]), ...........sub_string_testvec[u][size of x]) at element number u in vetor (test_Pattern_after_filling) I mean element u at vector contains all sub_string_testvec[u][0].......sub_string_testvec[u][x size]

    can I do this please help I want it ASAP
    my code :
    \code
    for ( int u=0; u< Orig_test_Pattern.size();u++){
    StringTokenizer token7 = new StringTokenizer(Orig_test_Pattern.get(u).toString( ));
    int token7_num=token7.countTokens();
    token7.nextToken();

    for(int x=0;x<token7_num-1;x++){
    if ( token7.hasMoreTokens()){
    String ff= token7.nextToken();
    for ( int g=0;g<input_node_no;g++){
    sub_string_testvec=new String [Orig_test_Pattern.size()][token7_num-1];
    if ( ff.substring(2,3).equals("x") && xxx==1 && input_more_1[g].equals(ff.substring (0,1)) && fl==1 ){
    sub_string_testvec[u][x]=ff.substring(0,2)+"1";
    }
    else if ( ff.substring(2,3).equals("x") && xxx==0){
    if (input_more_1[g]!=null){
    if (input_more_1[g].equals(ff.substring (0,1))&& fl==1 ){
    sub_string_testvec[u][x]=ff.substring(0,2)+"0"; }}
    }
    else{
    sub_string_testvec[u][x]=ff.substring(0,2)+ff.substring(2,3);}}}


    }}/ code

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Please use code tags when posting code so it is easier to read it.

    Are you trying to implement simple matrix addition?

  3. #3
    sara12345 is offline Member
    Join Date
    Dec 2009
    Posts
    59
    Rep Power
    0

    Default

    no I have a vector and I want to update each line in vector by using token because the line in vector contains some space and using substring becuse I want to change character in certain string in line and then after that I want to add the updated line in new vector
    the code is :
    [code]
    for ( int u=0; u< Orig_test_Pattern.size();u++){
    StringTokenizer token7 = new StringTokenizer(Orig_test_Pattern.get(u).toString( ));
    int token7_num=token7.countTokens();
    token7.nextToken();

    for(int x=0;x<token7_num-1;x++){
    if ( token7.hasMoreTokens()){
    String ff= token7.nextToken();
    for ( int g=0;g<input_node_no;g++){
    sub_string_testvec=new String [Orig_test_Pattern.size()][token7_num-1];
    if ( ff.substring(2,3).equals("x") && xxx==1 && input_more_1[g].equals(ff.substring (0,1)) && fl==1 ){
    sub_string_testvec[u][x]=ff.substring(0,2)+"1";
    }
    else if ( ff.substring(2,3).equals("x") && xxx==0){
    if (input_more_1[g]!=null){
    if (input_more_1[g].equals(ff.substring (0,1))&& fl==1 ){
    sub_string_testvec[u][x]=ff.substring(0,2)+"0"; }}
    }
    else{
    sub_string_testvec[u][x]=ff.substring(0,2)+ff.substring(2,3);}}}


    }}[\code]

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    So what happens when you run your code?

  5. #5
    sara12345 is offline Member
    Join Date
    Dec 2009
    Posts
    59
    Rep Power
    0

    Default

    Java Code:
    for ( int u=0; u< Orig_test_Pattern.size();u++){
    StringTokenizer token7 = new StringTokenizer(Orig_test_Pattern.get(u).toString( ));
    int token7_num=token7.countTokens();
    token7.nextToken();
    
    for(int x=0;x<token7_num-1;x++){
    if ( token7.hasMoreTokens()){
    String ff= token7.nextToken();
    for ( int g=0;g<input_node_no;g++){
    sub_string_testvec=new String [Orig_test_Pattern.size()][token7_num-1];
    if ( ff.substring(2,3).equals("x") && xxx==1 && input_more_1[g].equals(ff.substring (0,1)) && fl==1 ){
    sub_string_testvec[u][x]=ff.substring(0,2)+"1"; 
    }
    else if ( ff.substring(2,3).equals("x") && xxx==0){
    if (input_more_1[g]!=null){
    if (input_more_1[g].equals(ff.substring (0,1))&& fl==1 ){
    sub_string_testvec[u][x]=ff.substring(0,2)+"0"; }}
    }
    else{
    sub_string_testvec[u][x]=ff.substring(0,2)+ff.substring(2,3);}}}
    
    
    }}

  6. #6
    sara12345 is offline Member
    Join Date
    Dec 2009
    Posts
    59
    Rep Power
    0

    Default

    it just print all elements of two dimentional array. I want to add all elements of x in two dimentional array into elment u in vector how can I do this

  7. #7
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    So by adding do you mean string concatenation? Are they all strings that ytou just want to add together?
    What problem are you trying to solve by using these arrays and vectors?

  8. #8
    sara12345 is offline Member
    Join Date
    Dec 2009
    Posts
    59
    Rep Power
    0

    Default

    yes all of them strings
    I'm doing testing project related to test vecots

  9. #9
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Well I don't see any vector definitions in your program.

    Basically a two dimensional array is an array of arrays.
    So a 2D array of Strings is an array containing arrays of Strings. To add the strings in the 2D array, you need to know which arrays you are taking the strings from.

    Suppose we want to add all the strings in the first array of the 2D array, we would just do.
    Java Code:
    //String[][] twoDArray = .....
    String result = "";
    for(int i = 0 ; i <twoDArray[0].length;i++) {
        result += twoDArray[0][i];
    }
    Then to set that result to a position somePosition in a vector you just do
    Java Code:
    myVector.set(somePosition , result);

  10. #10
    sara12345 is offline Member
    Join Date
    Dec 2009
    Posts
    59
    Rep Power
    0

    Default

    thanks alot
    I will try this solution and then tell you what happens

  11. #11
    sara12345 is offline Member
    Join Date
    Dec 2009
    Posts
    59
    Rep Power
    0

Similar Threads

  1. Converting an Array to a Vector
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 08:44 PM
  2. Adding a double element to a vector
    By peachyco in forum New To Java
    Replies: 5
    Last Post: 11-25-2007, 06:07 PM
  3. Array or Vector
    By ravian in forum New To Java
    Replies: 2
    Last Post: 11-18-2007, 06:19 PM
  4. array vs Vector
    By paty in forum New To Java
    Replies: 1
    Last Post: 08-02-2007, 07:07 PM

Posting Permissions

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