Java中的字符串拼接

时间:2022-05-13 16:35:05

Java中的字符串拼接

1、设计源码

/**
 * @Title:IndexOf.java
 * @Package:com.you.freemarker.model
 * @Description:
 * @author:Youhaidong(游海东)
 * @date:2014-6-7 下午11:11:05
 * @version V1.0
 */
package com.you.freemarker.model;

/**
 * 类功能说明
 * 类修改者 修改日期
 * 修改说明
 * <p>Title:IndexOf.java</p>
 * <p>Description:游海东个人开发</p>
 * <p>Copyright:Copyright(c)2013</p>
 * @author:游海东
 * @date:2014-6-7 下午11:11:05
 * @version V1.0
 */
public class IndexOf
{
	/**
	 *
	 * @Title:indexOfStr
	 * @Description:
	 * @param:@return
	 * @return:String
	 * @throws
	 */
	public static String indexOfStr()
	{
		StringBuilder sb = new StringBuilder();
		String str = "水果,总数,总数|树木,总数,总数|水果,苹果,总数";
		String str1 = "";
		String[] result = str.split("\\|");
		for(int i=0;i<result.length;i++)
		{
			if(result[i].indexOf(",总数,总数") > 0)
			{
				str1 += "'" + result[i].substring(0, 2) + "'" + ",";
			}
		}
		str1 = "(" + str1.substring(0,str1.length()-1) + ")";
		sb.append("select t.fruit in");
		sb.append(str1);
		return sb.toString();
	}

	/**
	 * @Title:main
	 * @Description:
	 * @param:@param args
	 * @return: void
	 * @throws
	 */
	public static void main(String[] args)
	{
		String fruit = indexOfStr();
		System.out.println(fruit);
	}

}

2、设计结果

select t.fruit in('水果','树木')