Results 1 to 4 of 4
  1. #1
    doha786 is offline Member
    Join Date
    Mar 2009
    Posts
    48
    Rep Power
    0

    Arrow return array problem

    hi,
    the method of my program suppose to return many values that i can call from main method and show in JTable. But it just showing the last one..
    Java Code:
    public String[][] process(String searchName, String value){
    ..
    FileReader reader;                      
    String[][] row=new String[][]{};
    
    Map<String, File> names = new HashMap<String, File>();
    
    try{  
    ..
    ...
    
     for (String found: names.keySet()) {
    ..
    ..
    [b]row =new String[][]{{found, file.getName(), Long.toString(file.length())}};[/b]
    }
    }
    catch(Exception e) {e.printStackTrace() }
     
    return row;
    without array, last time i used for String :
    row+=found+"\t"+file.getName()+"\t"+file.length()+ "\n";
    so, can i make it for this 2D array ?
    please help..
    what we are thinking, it might not be true

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    You're overwriting your String[][] on every loop. You have to append:
    Java Code:
    String[][] row= null;
    
    Map<String, File> names = new HashMap<String, File>();
    
    try{  
    ..
    ...
    row = new String[names.keySet().size()][];
    int i = 0;
     for (String found: names.keySet()) {
    ..
    ..
    row[i] =new String[]{found, file.getName(), Long.toString(file.length())};
    i++;
    }
    }
    catch(Exception e) {e.printStackTrace() }
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    doha786 is offline Member
    Join Date
    Mar 2009
    Posts
    48
    Rep Power
    0

    Default

    great.......

    how can i appreciate you ?

    really thanks a lot..........
    what we are thinking, it might not be true

  4. #4
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Quote Originally Posted by doha786 View Post
    great.......

    how can i appreciate you ?

    really thanks a lot..........
    By clicking that little 'REP' button below my post.

    You're welcome.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

Similar Threads

  1. How do i return a random String from an array?
    By Grendel0 in forum New To Java
    Replies: 9
    Last Post: 03-11-2010, 10:11 AM
  2. Problem with recurrsive return statement
    By pachufir in forum New To Java
    Replies: 3
    Last Post: 12-08-2009, 02:32 AM
  3. problem while using return statement
    By shaluchandran in forum New To Java
    Replies: 10
    Last Post: 12-12-2008, 06:29 PM
  4. return new variable -problem
    By Hevonen in forum New To Java
    Replies: 7
    Last Post: 12-08-2008, 06:07 AM
  5. Replies: 2
    Last Post: 04-16-2008, 12:35 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
  •