-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStr.java
68 lines (51 loc) · 1.9 KB
/
Str.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;
import com.google.gson.Gson;
import com.alibaba.fastjson.JSON;
import com.cctvmall.entity.User;
public class Str
{
public static void main(String args[])
{
String username = "chen jian ping";
System.out.println(username);
System.out.println(username.charAt(2));
// System.out.println(username.codePointAt(2));
System.out.println(username.concat("Li Ming"));
System.out.println(username.contains("ping"));
List<String> stu = new ArrayList<>();
stu.add("chen");
stu.add("jian");
stu.add("ping");
Iterator it = stu.iterator();
while(it.hasNext()) {
String str = (String)it.next();
System.out.println(str);
}
List<String> stu1 = new ArrayList<String>();
stu1.add("³Â");
stu1.add("½¨");
stu.addAll(1, stu1);
Gson g = new Gson();
System.out.println(g.toJson(stu));
for(int i = 0; i < stu.size(); i = i + 1) {
System.out.println(stu.get(i));
}
Map<String, Object> stu2 = new HashMap<String, Object>();
stu2.put("name", "chen");
stu2.put("age", 23);
stu2.put("data", stu);
System.out.println(g.toJson(stu2));
System.out.println(JSON.toJSONString(stu2));
String array_json = "[{'id':1,'username':'ÕÅ·É','age':68},{'id':2,'username':'ÕÔÔÆ','age':78}]";
List<User> users = JSON.parseArray(array_json, User.class);
// System.out.println(g.toJson(users));
for(int j = 0; j < users.size(); j = j + 1) {
User user = users.get(j);
System.out.println(user.getUsername());
}
}
}