Scenario:
Do you want to write SQL files in the background to access the database?
String SQL = "select a," + "B," + "C" + "from table ";
When the SQL statement is short, how many "+" and "should be written if it is long? So I want to write a tool class to solve the problem of Long String concatenation.
Code:
Import Java. util. arraylist; import Java. util. handler; public class gensqlstring {/*** process Long String concatenation * @ Param ARGs */public static void main (string [] ARGs) {arraylist <string> array = new arraylist <string> (); region SCN = new region (system. in); string line; string restring; system. out. println ("Enter your long string"); // bufferedreader BR = new bufferedreader (New inputstreamreader (system. in); // string restring = "+ \" "+ B R. Readline () + "\" ";/** when the end is entered, press enter to end */while (! "End ". equals (line = SCN. nextline () {array. add (line);} system. out. println ("the result is: \ r \ n"); int I = 1; for (string STR: array) {if (I = 1) {restring = "\" "+ STR +" \ "";} else if (I = array. size () {restring = "+ \" "+ STR +" \ ";" ;}else {restring = "+ \" "+ STR + "\"";} system. out. println (restring); I ++ ;}}}
Although simple, it can be used to improve development efficiency.