- 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;
}