0
private static final String SQL_INSERT = "INSERT INTO ${table}(${keys}) VALUES(${values})";
private static final String SQL_CREATE = "CREATE TABLE ${table}(${keys} VARCHAR(20) NOT NULL)";
private static final String TABLE_REGEX = "\\$\\{table\\}";
private static final String KEYS_REGEX = "\\$\\{keys\\}";
private static final String VALUES_REGEX = "\\$\\{values\\}";

String[] headerRow = csvReader.readNext();//getting(Machine Name , Value)
String[] stripedHeaderRow = StringUtils.stripAll(headerRow);

String query2 = SQL_CREATE.replaceFirst(TABLE_REGEX, tableName);
query2 = query2.replaceFirst(KEYS_REGEX, StringUtils.join(headerRow, " VARCHAR(20) NOT NULL,"));

结果:

"Machine Name, Value"

预期结果:

"MachineName , Value"
4

3 回答 3

0

假设你的数组是temp可变的,

以下是如何修剪每个字符串之间的所有空格。

String[] temp = {"My Name Is", "And so Far", "All good", "Really?", 
                             "That makes no sense to me", "Oh! Somehthing Like This"};
Stream<String> stream = Arrays.stream(temp);
temp = stream.map(str -> str.replaceAll("\\s",""))
         .toArray(size -> new String[size]);

现在如果打印它,它会给这个..

for(String st : temp)
        System.out.println(st);

输出:-

MyNameIs
AndsoFar
Allgood
Really?
Thatmakesnosensetome
Oh!SomehthingLikeThis
于 2018-07-26T10:49:49.400 回答
0

您可以使用 JAVA 中的正则表达式来完成。例如:

String a = "Hello    World!!";
 a = a.replaceAll("\\s","");

现在的价值a = "HelloWorld!!"

于 2018-07-26T10:31:40.253 回答
0

我创建了 arrayList 来修改字符串内容的数组,

List<String> al = new ArrayList<String>();
for (String element: headerRow) 
     { 
         al.add(element.replace(' ', '_')); 

    }
String[] stripedHeaderRow = al.toArray(new String[al.size()]);//Creating new array of String

//这将实现我的结果。

于 2018-07-26T11:21:24.897 回答