Method editing strings of an Array List

Joined
Mar 13, 2012
Messages
2
Reaction score
0
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;
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top