Method editing strings of an Array List

Discussion in 'Java' started by gagirl1105, Mar 20, 2012.

  1. gagirl1105

    gagirl1105

    Joined:
    Mar 13, 2012
    Messages:
    2
    Hi, all! I'm working on an introductory Java assignment and am slightly confused on an Array List issue. Our assignment involves going through each String element of an Array list and changing every 'e' to a '-'. I've run into an issue in that I can cycle through the Strings but can't go through each character within that string. I've tried to set up two different for-loops but am now having issues setting a limit to the for-loop because the length I'm limiting it to is an integer. Any help would be appreciated. Here's what I have so far:
    Code:
    if(args.length <=10)
      {
           for (int i = 0; i < args.length; i++)
     
           {   
              String iString = Integer.toString(i); 
     
     
               for (int j = 0; j < iString.length; j++)
               {
               char ch  = args[i].charAt(j);                    
               if(ch == 'e')
                   {   String minus = "-";
                        newString += minus;
                   }
                 else
                 {
                       newString += Character.toString(ch);
                  }
     
            }
     
        }
       args[i] = newString;
    }
    
    gagirl1105, Mar 20, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Klaus Neuner
    Replies:
    7
    Views:
    462
    Klaus Neuner
    Jul 26, 2004
  2. Girish Sahani
    Replies:
    17
    Views:
    552
    Boris Borcic
    Jun 9, 2006
  3. Ben

    Strings, Strings and Damned Strings

    Ben, Jun 22, 2006, in forum: C Programming
    Replies:
    14
    Views:
    724
    Malcolm
    Jun 24, 2006
  4. gwanglu@gmail.com
    Replies:
    0
    Views:
    561
    gwanglu@gmail.com
    Jul 19, 2006
  5. OW Ghim Siong
    Replies:
    2
    Views:
    379
    Peter Otten
    Nov 30, 2010
Loading...

Share This Page