questjava
asked on
Some help with List and Itterator
In the following method List contains numbers ,
I need to mask those numbers and return them as **-***1234
for (Iterator it = getList().iterator(); it.hasNext();)
{
if (first)
{
buf.append(" | Number(s): ");
first = false;
}
else
{
buf.append(", ");
}
buf.append(it.next().toStr ing());
}
I need to mask those numbers and return them as **-***1234
for (Iterator it = getList().iterator(); it.hasNext();)
{
if (first)
{
buf.append(" | Number(s): ");
first = false;
}
else
{
buf.append(", ");
}
buf.append(it.next().toStr
}
So I guess your list is made up of Integer objects - correct?
Or it is made up if String's which are only digits?
Or it is made up if String's which are only digits?
ASKER
I ithink its strings
If its elements are Integer's, then the above code should work,
if its elementas are String;s, then insted of
---
int ii = it.next();
String s = "" + ii;
---
you should just use:
---
String s = it.next();
---
if its elementas are String;s, then insted of
---
int ii = it.next();
String s = "" + ii;
---
you should just use:
---
String s = it.next();
---
then this should work:
StringBuffer buf = new StringBuffer("| Numbers: " ):
for (Iterator it = getEinList().iterator(); it.hasNext();)
{
String s = it.next();
if(s.length() >4)buf.append("**-***" + s.substring(s.length()-4 ) + ",");
else buff.append(s);
}
ASKER
int ii =it.next();
or string ii =it.next();
error type mismatch .. cannot convet from object to string/int
or string ii =it.next();
error type mismatch .. cannot convet from object to string/int
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
it should be
String s = (String) it.next();
String s = (String) it.next();
This is the output of the code which I posted and ran, as above:
| Numbers: **-***5678,**-***1234,
Are you sure your list has String's?
Can you post how this list is declared/created ?
Can you post how this list is declared/created ?
ASKER
thank you ..it works
Open in new window