Results 1 to 5 of 5
  1. #1
    reverton is offline Member
    Join Date
    Apr 2013
    Posts
    11
    Rep Power
    0

    Default Store letters of strings from command line into array

    How can I store each letter of each args in a String Array without using charAt?
    This is what I was trying to do:
    Java Code:
           
                    String[][] strArray = new String[args.length][];
                    
                    int counter = 0;
                    	
                    for(int r = 0; r<args.length;r++){
                    	
                    	for(int c=0; c<args[i].length(); c++){
                    		
                    		strArray[r][c]= str.charAt(counter);
                    		
                    		counter++;
                    		
                    	}
                    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,563
    Blog Entries
    7
    Rep Power
    21

    Default Re: Store letters of strings from command line into array

    Maybe you want this:

    Java Code:
    char[][] copy= new char[args.length][];
    for (int i= 0; i < args.length; i++)
       copy[i]= args[i].toChararray();
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    reverton is offline Member
    Join Date
    Apr 2013
    Posts
    11
    Rep Power
    0

    Default Re: Store letters of strings from command line into array

    Hi, Jos. Thanks for your reply. Sorry I wasn't clear. Actually I need it to be stored especifically in a String Array.
    So if args[0]=abc and args[1]= def
    strArray[1,2] = e
    Cheers

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,563
    Blog Entries
    7
    Rep Power
    21

    Default Re: Store letters of strings from command line into array

    Quote Originally Posted by reverton View Post
    Hi, Jos. Thanks for your reply. Sorry I wasn't clear. Actually I need it to be stored especifically in a String Array.
    So if args[0]=abc and args[1]= def
    strArray[1,2] = e
    Cheers
    If that restriction still applies (no charAt( ... ) method; a silly restriction b.t.w.) you can build from my solution, i.e. create a String array from the char array ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    reverton is offline Member
    Join Date
    Apr 2013
    Posts
    11
    Rep Power
    0

    Default Re: Store letters of strings from command line into array

    Thanks!

Similar Threads

  1. concatenate command-line arguments as strings
    By Cracked in forum New To Java
    Replies: 1
    Last Post: 12-15-2012, 05:44 PM
  2. Replies: 2
    Last Post: 12-04-2011, 08:21 AM
  3. Replies: 16
    Last Post: 09-17-2011, 02:41 AM
  4. command line input to array
    By minusten in forum New To Java
    Replies: 13
    Last Post: 05-09-2011, 01:56 AM
  5. Replies: 22
    Last Post: 01-05-2009, 01:03 AM

Posting Permissions

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