-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathStringBadUse.java
More file actions
41 lines (32 loc) · 1.05 KB
/
StringBadUse.java
File metadata and controls
41 lines (32 loc) · 1.05 KB
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
public class StringBadUse {
public static void main(String[] args) {
// StringBuffer Methods
// CUD (Create (Add) , Update , Delete)
// H e l l o
StringBuilder sb2 = new StringBuilder(); // Java 5 Onwards
// There is no synchronized method in StringBuilder
// StringBuffer all methods are synchronized
//StringBuffer sb2 = new StringBuffer();
sb2.append("Hello"); // Append at End
sb2.reverse();
//sb2.insert(0, "Hi");
//sb2.deleteCharAt(0); // Single Char delete
sb2.delete(1, 3); // 1st is index and 3 is position
sb2.setCharAt(0, 'T'); // Update
System.out.println(sb2);
// Advance Search
//String x = "hello"+"bye";
double price = 9000;
String brand = "nokia";
//String sql = "select * from product";
StringBuffer sb = new StringBuffer("select * from product");
if(price>0){
sb.append("where price>=").append(price);
//sql = sql + " where price>="+price;
}
if(brand!=null && brand.length()>0){
sb.append("and brand='").append(brand).append("'");
//sql = sql +" and brand='"+brand+"'";
}
}
}