1. Is a string final?

1 String str="asdfdf "; 2 str.replace("as "," "); 3 System.out.println(str); //asdfdf 4 str=str.replace("as "," "); 5 System.out.println(str); //dfdfCopy the code

2. String cutting

Get parameters based on url:

enterId = Long.parseLong(target.split(“/ “)[2]); This will deal with the problem of slicing strings. The splitAPI looks like this:

Public String[] split(String regex,int limit) splits the String based on matching the given regular expression. This method returns an array containing substrings of this string, each terminated by another substring that matches the given expression, or by the end of the string. The substrings in the array are arranged in the order in which they appear in the string. If the expression does not match any part of the input, the resulting array has only one element, the string. The limit parameter controls the number of times the pattern is applied, thus affecting the length of the resulting array. If the limit n is greater than 0, the pattern will be applied at most n-1 times, the array length will not be greater than n, and the last entry of the array will contain all inputs beyond the last matched delimiter. If n is not positive, the pattern will be applied as many times as possible, and the array can be of any length. If n is 0, the pattern is applied as many times as possible, the array can be of any length, and an empty ending string is discarded.

For example, the string “boo:and:foo “yields the following results with these parameters:

2 {“boo “, “and:foo “} : 5 {“boo “, “and “, “foo “} : 2 {“boo “, “and “, “foo “} : -2 { “boo “, “and “, “foo ” } o 5 { “b “, ” “, “:and:f “, ” “, ” ” } o -2 { “b “, ” “, “:and:f “, ” “, ” ” } o 0 { “b “, ” “, “:and:f ” }

Public String[] split(String regex) Splits the String based on the match of the given regular expression. This method acts like calling the two-argument split method with the given expression and the constraint argument 0. Therefore, the resulting array does not contain an empty terminating string.

For example, the string “boo:and:foo “yields the following results using these expressions:

Regex results: {” boo “, “and”, “foo”} o {” b “, “”,” : the and: f “}

Parameters: Regex – Delimited regular expression Returns: array of strings, which are split based on the given regular expression’s match this string is determined by throwing: PatternSyntaxException – If the regular expression’s syntax is invalid

3. Nullify the JSON string

There are some empty values in the database, and there are two more key-value pairs at the end. Of course, there are also some problems. Poor grasp of SQL, so chose to use Java processing, update the database.

The data objects processed look like this:

1 '{\"showImg_1\ ":\"/upload/webHome/template/4ddedebb-7615-4686-b27a-b515a6a5a2cc.jpg\ ",\"showImg_2\ ":\"/upload/webHome/template/2c0806ee-6165-4b95-949d-340ddad18171.jpg\ ",\"showImg_3\ ":\"/upload/webHome/template/35464a57-a987-4e40-91b4-f5b33e343f46.jpg\ ",\"showImg_4\ ":\"/upload/webHome/template/9bddbbd6-1ad2-4290-b087-caa26bf93197.jpg\ ",\"showImg_5\ ":\"/upload/webHome/template/604b7531-384b-4052-93cb-e5d51182023b.jpg\ ",\"showImg_6\ ":\"/upload/webHome/template/4673cf82-fa07-4acc-ac7c-e5c7ef9af687.jpg\ ",\"showImg_7\":\"\",\"showImg_8\":\"\",\"emplate.quickmark\":\"/upload/webHome/template/27b4cb88-b3b2-4046-bedd-c4ad927 35310.jpg\",\" emplate.img\":\"/upload/webHome/template/7949e9eb-eb86-4d54-ab09-1271ea202b2e.jpg\"}'Copy the code

Jfinal framework used:

Public void manageSQL(){5 String SQL ="select * from _table"; 6 List<Record> list=Db.find(sql); 7 setAttr("length",list.size()); 8 for(int i=0; i<list.size(); I ++){9 Record r=list.get(I); 12 String json= r.getstr ("showImg"); 13 setAttr("old=",json); 15 int ind= json.indexof (",\"emplate"); 16 if(ind>0){ 17 json=json.substring(0, ind)+"}"; 18 } 19 setAttr("new=",json); 21 json=json.replaceAll("(? <=\\{)\"\\w+\":\"\",|,*\"\\w+\":\"\")", ""); 22 setAttr("all:"+i,json); 23 24 System.out.println(json+"========="); 27 r.set("showImg", json); 28 29 Db.update("home_template",r); 30 31 } 32 33 renderJson(); 34}Copy the code

4. Some methods on String:

Length () – Returns the length, unlike js, which has the length attribute.

Length: Array length -length; List length -size();

    



This article from Ryan. Miao blog garden, the original link: http://www.cnblogs.com/woshimrf/p/4605205.html, if you want to reprint, please contact our author