情景
你在后台写sql文访问数据库时是不是要这样写
String sql=select a
+b
+c
+from table;
String sql=select a
+b
+c
+from table;
当sql语句短还好要是长了该写多少个+和啊于是就想写一个工具类处理长字符串拼接的问题
代码
import javautilArrayList;
import javautilScanner;
public class GenSqlString {
/**
* 处理长字符串拼接
* @param args
*/
public static void main(String[] args) {
ArrayList<String> array = new ArrayList<String>();
Scanner scn = new Scanner(Systemin);
String line;
String reString;
Systemoutprintln(请输入您的长字符串);
//BufferedReader br=new BufferedReader(new InputStreamReader(Systemin));
//String reString=+\+brreadLine()+ \;
/** 当输入end时回车结束*/
while (!endequals(line = scnnextLine())) {
arrayadd(line);
}
Systemoutprintln(The result is: \r\n);
int i=;
for(String str : array){
if(i==){
reString=\+str+ \;
}else if(i==arraysize()){
reString=+\+str+ \;;
}else{
reString=+\+str+ \;
}
Systemoutprintln(reString);
i++;
}
}
}
import javautilArrayList;
import javautilScanner;
public class GenSqlString {
/**
* 处理长字符串拼接
* @param args
*/
public static void main(String[] args) {
ArrayList<String> array = new ArrayList<String>();
Scanner scn = new Scanner(Systemin);
String line;
String reString;
Systemoutprintln(请输入您的长字符串);
//BufferedReader br=new BufferedReader(new InputStreamReader(Systemin));
//String reString=+\+brreadLine()+ \;
/** 当输入end时回车结束*/
while (!endequals(line = scnnextLine())) {
arrayadd(line);
}
Systemoutprintln(The result is: \r\n);
int i=;
for(String str : array){
if(i==){
reString=\+str+ \;
}else if(i==arraysize()){
reString=+\+str+ \;;
}else{
reString=+\+str+ \;
}
Systemoutprintln(reString);
i++;
}
}
}
虽然简单点但是能用就行提高开发效率嘛