Java concatenation string to remove the last redundant comma method _java

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.