The example in this article describes the method of removing the last redundant comma when the Java concatenation string is used. Share to everyone for your reference. The specific analysis is as follows:
Let's look at the following code:
for (int t = 0; t < Memberlen t++) {
memtemp = Staffermap.get (strmember[t));
if (memtemp!= null) {
Membernames + = Memtemp + ",";
}
}
The above code, the concatenation of the string will be more than one "," such as: "STR1,STR2,STR3," to remove the comma after STR3, you can use the following methods:
Membernames = membernames.substring (0,membernames.length ()-1);
Like when Team1=test ', ' u1-team ', ' v-team ', '
How to change to:
team1= ' test ', ' u1-team ', ' V-team '
Available:
Team1 = "'" + team1.substring (0, team1.length-2);
The following are additional users:
If stitching can use the following code
StringBuilder SDB = new StringBuilder ();
for (int t = 0; t < Memberlen t++)
{
memtemp = Staffermap.get (strmember[t));
if (memtemp!= null)
{
if (sbd.length > 0)
{
sbd.append (","). Append (memtemp);
else{
sbd.append (memtemp);
}} System.out.prentln ("No extra comma:" + sbd.tostring ());
I hope this article will help you with your Java programming.