zhuguifei
2026-03-10 2c1fd10c6fbabb8e9f0e9f07fe66fb36c008e883
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
package com.shlanbao.tzsc.utils.tools;
 
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
 
/**
 * 字符串处理工具类
 * <li>@author Leejean
 * <li>@create 2014-6-24 下午04:13:57
 */
public class StringUtil {
 
    public static boolean isFloat(String str){
        try {
            Float.parseFloat(str);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
 
    public static Float convert2Float(Object obj){
        float r=0.0F;
        String str=convertObjToString(obj);
        if(isFloat(str)){
            r=Float.parseFloat(str);
        }
        return r;
    }
 
    public static Integer convert2Integer(Object obj){
        int r=0;
        String str=convertObjToString(obj);
        if(isInteger(str)){
            r=Integer.parseInt(str);
        }
        return r;
    }
 
    /**
     * 去除两端空格
     * @param str
     * @return
     */
    public static String trim(String str) {
        if ((null!=str) && (!"".equals(str))) {
            return str.trim();
        }
        return str;
    }
    /**
     * 不为"","   ","null","NULL",NULL 时返回true
     * @param obj
     * @return
     */
    public static boolean notEmpty(Object obj){
        if(obj==null){
            return false;
        }else if(obj.toString().trim().equals("")){
            return false;
        }else if(obj.toString().trim().equalsIgnoreCase("null")){
            return false;
        }
        return true;
    }
    public static Double converObj2Double(Object o){
        Double res=0D;
        try {
            res=Double.valueOf(o.toString());
        } catch (Exception e) {
        }
        return res;
    }
    public static Long converObj2Long(Object o){
        Long res=0L;
        try {
            res=Long.valueOf(o.toString());
        } catch (Exception e) {
        }
        return res;
    }
    public static String convertObj(Object o){
        if(o==null){
            return null;
        }else{
            return o.toString().trim();
        }
    }
    /**
     * 判断字符串是否为空
     * @param str
     * @return true 不为空 false 空
     */
    public static boolean notNull(String str) {
        if ((null!=str) && (!"".equals(str.trim()))) {
            return true;
        }
        return false;
    }
    /**
     * 判断字符串是否是Integer类型
     * @param str
     * @return
     */
    public static boolean isInteger(String str){
        try{
            Integer.parseInt(str.trim());
            return true;
        }catch(Exception ex){
            return false;
        }
    }
    /**
     * 判断字符串是否是Double类型
     * @param str
     * @return
     */
    public static boolean isDouble(String str){
        try{
            Double.parseDouble(str.trim());
            return true;
        }catch(Exception ex){
            return false;
        }
    }
 
    public static String convertObjToString(Object o){
        if(null!=o){
            return o.toString();
        }else{
            return "";
        }
    }
 
    public static Double convertObjToDouble(Object o){
        if(null!=o){
            return Double.parseDouble(o.toString());
        }else{
            return 0.0;
        }
    }
 
    public static Double convertObjTox100Double(Object o){
        if(null!=o){
            DecimalFormat df = new DecimalFormat("#");
            double v = Double.parseDouble(o.toString());
 
            String format = df.format(v*100);
            return Double.parseDouble(format);
        }else{
            return 0.0;
        }
    }
    /**
     * 分割字符串
     * @param params 被分割的字符串
     * @param splitChar 分割字符
     * @return List<Long>
     */
    public static List<Long> splitToLongList(String params, String splitChar) {
        List<Long> longlist = new ArrayList<Long>();
        if(params==null||params.trim().equals("")){return longlist;}
        String param[] = params.split(splitChar);
        for (String string : param) {
            if(string.equals("")){
                longlist.add(null);
            }else{
                longlist.add(Long.parseLong(string));
            }
        }
        return longlist;
    }
    /**
     * 将字符串转换为String数组
     * @param params
     * @param splitChar
     * @return
     */
    public static List<String> splitToStringList(String params, String splitChar) {
        List<String> stringlist = new ArrayList<String>();
        if(params==null||params.trim().equals("")){return stringlist;}
        String param[] = params.split(splitChar);
        for (String string : param) {
            if(string.equals("")){
                stringlist.add(null);
            }else{
                stringlist.add(string);
            }
        }
        return stringlist;
    }
    /**
     * 将字符串转换为Integer数组
     * @param params
     * @param splitChar
     * @return
     */
    public static List<Integer> splitToIntegerList(String params, String splitChar) {
        List<Integer> longlist = new ArrayList<Integer>();
        if(params==null||params.trim().equals("")){return longlist;}
        if(!params.trim().equals("")){
            String param[] = params.split(splitChar);
            for (String string : param) {
                if(string.equals("")){
                    longlist.add(null);
                }else{
                    longlist.add(Integer.parseInt(string));
                }
            }
        }
        return longlist;
    }
    /**
     * 将字符串转换为Double数组
     * @param params
     * @param splitChar
     * @return
     */
    public static List<Double> splitToDouble(String params, String splitChar) {
        List<Double> longlist = new ArrayList<Double>();
        if(params==null||params.trim().equals("")){return longlist;}
        if(!params.trim().equals("")){
            String param[] = params.split(splitChar);
            for (String string : param) {
                if(string.equals("")){
                    longlist.add(null);
                }else{
                    longlist.add(Double.parseDouble(string));
                }
            }
        }
        return longlist;
    }
    /**
     * 格式化
     * @author Leejean
     * @create 2014年9月16日下午2:13:17
     * @param from
     * @param to
     * @return
     */
    public static String fmtDateBetweenParams(String o_date,String from,String to){
        if(StringUtil.notNull(from)||StringUtil.notNull(to)){
            if(!StringUtil.notNull(from)){
                return " and ( "+o_date+" <= to_date('"+to+"','yyyy-MM-dd') ) ";
            }
            if(!StringUtil.notNull(to)){
                return " and ( "+o_date+" >= to_date('"+from+"','yyyy-MM-dd') ) ";
            }
            return " and ("+o_date+" between to_date('"+from+"','yyyy-MM-dd') and to_date('"+to+"','yyyy_MM-dd')) ";
        }
        return "";
    }
 
    /**
     * oracle 日期格式化
     * @param o_date
     * @param from
     * @param to
     * @return
     */
    public static String OraclefmtDateBetweenParams(String o_date,String from,String to){
        if(StringUtil.notNull(from)||StringUtil.notNull(to)){
            if(!StringUtil.notNull(from)){
                return " and ( "+o_date+" <= to_date('"+to+"','SYYYY-MM-DD HH24:MI:SS') ) ";
            }
            if(!StringUtil.notNull(to)){
                return " and ( "+o_date+" >= to_date('"+from+"','SYYYY-MM-DD HH24:MI:SS') ) ";
            }
            return " and ("+o_date+" between to_date('"+from+"','SYYYY-MM-DD HH24:MI:SS') and to_date('"+to+"','SYYYY-MM-DD HH24:MI:SS')) ";
        }
        return "";
    }
    /**
     * 格式化
     * @author bsw
     * @create 2018年3月5日
     * @param from
     * @param to
     * @return
     */
    public static String fmtDateHHmmssBetweenParams(String o_date,String from,String to){
        if(StringUtil.notNull(from)||StringUtil.notNull(to)){
            if(!StringUtil.notNull(from)){
                return " and ( "+o_date+" <= to_date('"+to+"','yyyy-MM-dd HH24:mi:ss') ) ";
            }
            if(!StringUtil.notNull(to)){
                return " and ( "+o_date+" >= to_date('"+from+"','yyyy-MM-dd HH24:mi:ss') ) ";
            }
 
            return " and ("+o_date+" between to_date('"+DateUtil.getDateStart(from)+"','yyyy-MM-dd HH24:mi:ss') and to_date('"+DateUtil.getDateEnd(to)+"','yyyy_MM-dd HH24:mi:ss')) ";
        }
        return "";
    }
    /**
    * @Title: arrayToString
    * @Description: String数组转 sql语句中的in '','',''
    * @param  params
    * @return String   返回类型
    * @throws
     */
    public static String arrayToStringBySqlin(String[] params){
        String returnString="";
        for(int i=0;i<params.length;i++){
            if(StringUtil.notNull(params[i])){
                if(i==params.length-1){
                    returnString+="'"+params[i]+"' ";
                }else{
                    returnString+="'"+params[i]+"',";
                }
            }
        }
        return returnString;
    }
 
 
    /**
     * 判断字符串是否为null,如果为null返回空
     * */
    public static String nullToString(String str){
        if(str == null ){
            return "";
        }else{
            return str;
        }
    }
 
    /**
     * 最大值,最小值
     * // type 1:最大值  2:最小值  args:数组
     *
     * */
    public static Double getMaxAndMinVal(Double A[],int type){
        Double min,max;
        //Double A[]={74.5,48.9,30.2,17.1,62.0};  // 声明整数数组A,并赋初值
        min=max=A[0];
        for(int i=0;i<A.length;i++){
            if(A[i]>max){   // 判断最大值
              max=A[i];
            }
            if(A[i]<min){   // 判断最小值
               min=A[i];
            }
        }
        //System.out.println("\n数组的最大值是:"+max); // 输出最大值
        //System.out.println("数组的最小值是:"+min); // 输出最小值
        if(type==1){
            return max;
        }else{
            return min;
        }
    }
}