1 public class ArraysUtil {
2
3
4 /**
5 * 升序排列一个byte数组
6 * @param arr 要排序的byte数组
7 */
8 public static void sortASC(byte[] arr){
9 for (int i = 0; i < arr.length-1; i++) {
10 for (int j = 0; j < arr.length-i-1; j++) {
11 if(arr[j]>arr[j+1]){
12 byte temp = arr[j];
13 arr[j]=arr[j+1];
14 arr[j+1]=temp;
15 }
16 }
17 }
18 }
19
20 /**
21 * 升序排列一个short数组
22 * @param arr 要排序的short数组
23 */
24 public static void sortASC(short[] arr){
25 for (int i = 0; i < arr.length-1; i++) {
26 for (int j = 0; j < arr.length-i-1; j++) {
27 if(arr[j]>arr[j+1]){
28 short temp = arr[j];
29 arr[j]=arr[j+1];
30 arr[j+1]=temp;
31 }
32 }
33 }
34 }
35
36 /**
37 * 升序排列一个int数组
38 * @param arr 要排序的int数组
39 */
40 public static void sortASC(int[] arr){
41 for (int i = 0; i < arr.length-1; i++) {
42 for (int j = 0; j < arr.length-i-1; j++) {
43 if(arr[j]>arr[j+1]){
44 int temp = arr[j];
45 arr[j]=arr[j+1];
46 arr[j+1]=temp;
47 }
48 }
49 }
50 }
51
52 /**
53 * 升序排列一个long数组
54 * @param arr 要排序的long数组
55 */
56 public static void sortASC(long[] arr){
57 for (int i = 0; i < arr.length-1; i++) {
58 for (int j = 0; j < arr.length-i-1; j++) {
59 if(arr[j]>arr[j+1]){
60 long temp = arr[j];
61 arr[j]=arr[j+1];
62 arr[j+1]=temp;
63 }
64 }
65 }
66 }
67
68 /**
69 * 升序排列一个char数组
70 * @param arr 要排序的char数组
71 */
72 public static void sortASC(char[] arr){
73 for (int i = 0; i < arr.length-1; i++) {
74 for (int j = 0; j < arr.length-i-1; j++) {
75 if(arr[j]>arr[j+1]){
76 char temp = arr[j];
77 arr[j]=arr[j+1];
78 arr[j+1]=temp;
79 }
80 }
81 }
82 }
83
84 /**
85 * 升序排列一个float数组
86 * @param arr 要排序的float数组
87 */
88 public static void sortASC(float[] arr){
89 for (int i = 0; i < arr.length-1; i++) {
90 for (int j = 0; j < arr.length-i-1; j++) {
91 if(arr[j]>arr[j+1]){
92 float temp = arr[j];
93 arr[j]=arr[j+1];
94 arr[j+1]=temp;
95 }
96 }
97 }
98 }
99
100 /**
101 * 升序排列一个double数组
102 * @param arr 要排序的byte数组
103 */
104 public static void sortASC(double[] arr){
105 for (int i = 0; i < arr.length-1; i++) {
106 for (int j = 0; j < arr.length-i-1; j++) {
107 if(arr[j]>arr[j+1]){
108 double temp = arr[j];
109 arr[j]=arr[j+1];
110 arr[j+1]=temp;
111 }
112 }
113 }
114 }
115
116 /**
117 * 降序排列一个byte数组
118 * @param arr 要排序的byte数组
119 */
120 public static void sortDESC(byte[] arr){
121 for (int i = 0; i < arr.length-1; i++) {
122 for (int j = 0; j < arr.length-i-1; j++) {
123 if(arr[j]<arr[j+1]){
124 byte temp = arr[j];
125 arr[j]=arr[j+1];
126 arr[j+1]=temp;
127 }
128 }
129 }
130 }
131
132 /**
133 * 降序排列一个short数组
134 * @param arr 要排序的short数组
135 */
136 public static void sortDESC(short[] arr){
137 for (int i = 0; i < arr.length-1; i++) {
138 for (int j = 0; j < arr.length-i-1; j++) {
139 if(arr[j]<arr[j+1]){
140 short temp = arr[j];
141 arr[j]=arr[j+1];
142 arr[j+1]=temp;
143 }
144 }
145 }
146 }
147
148 /**
149 * 降序排列一个int数组
150 * @param arr 要排序的int数组
151 */
152 public static void sortDESC(int[] arr){
153 for (int i = 0; i < arr.length-1; i++) {
154 for (int j = 0; j < arr.length-i-1; j++) {
155 if(arr[j]<arr[j+1]){
156 int temp = arr[j];
157 arr[j]=arr[j+1];
158 arr[j+1]=temp;
159 }
160 }
161 }
162 }
163
164 /**
165 * 降序排列一个long数组
166 * @param arr 要排序的long数组
167 */
168 public static void sortDESC(long[] arr){
169 for (int i = 0; i < arr.length-1; i++) {
170 for (int j = 0; j < arr.length-i-1; j++) {
171 if(arr[j]<arr[j+1]){
172 long temp = arr[j];
173 arr[j]=arr[j+1];
174 arr[j+1]=temp;
175 }
176 }
177 }
178 }
179
180 /**
181 * 降序排列一个float数组
182 * @param arr 要排序的float数组
183 */
184 public static void sortDESC(float [] arr){
185 for (int i = 0; i < arr.length-1; i++) {
186 for (int j = 0; j < arr.length-i-1; j++) {
187 if(arr[j]<arr[j+1]){
188 float temp = arr[j];
189 arr[j]=arr[j+1];
190 arr[j+1]=temp;
191 }
192 }
193 }
194 }
195
196 /**
197 * 降序排列一个double数组
198 * @param arr 要排序的double数组
199 */
200 public static void sortDESC(double[] arr){
201 for (int i = 0; i < arr.length-1; i++) {
202 for (int j = 0; j < arr.length-i-1; j++) {
203 if(arr[j]<arr[j+1]){
204 double temp = arr[j];
205 arr[j]=arr[j+1];
206 arr[j+1]=temp;
207 }
208 }
209 }
210 }
211
212 /**
213 * 降序排列一个char数组
214 * @param arr 要排序的char数组
215 */
216 public static void sortDESC(char[] arr){
217 for (int i = 0; i < arr.length-1; i++) {
218 for (int j = 0; j < arr.length-i-1; j++) {
219 if(arr[j]<arr[j+1]){
220 char temp = arr[j];
221 arr[j]=arr[j+1];
222 arr[j+1]=temp;
223 }
224 }
225 }
226 }
227
228 /**
229 * 在给定的int数组中查询指定的int元素第一次出现的位置
230 * @param arr 给定的int 数组
231 * @param seek 要查询的int 元素
232 * @return 如果找到元素,返回元素的索引;如果未找到元素,返回-1
233 */
234 public static int firstIndexOf(int[] arr,int seek){
235 for (int i = 0; i < arr.length; i++) {
236 if (arr[i]==seek){
237 return i;
238 }
239 }
240 return -1;
241
242 }
243
244 /**
245 * 在给定的byte数组中查询指定的byte元素第一次出现的位置
246 * @param arr 给定的byte 数组
247 * @param seek 要查询的byte 元素
248 * @return 如果找到元素,返回元素的索引;如果未找到元素,返回-1
249 */
250 public static int firstIndexOf(byte[] arr,byte seek){
251 for (int i = 0; i < arr.length; i++) {
252 if (arr[i]==seek){
253 return i;
254 }
255 }
256 return -1;
257
258 }
259
260 /**
261 * 在给定的short数组中查询指定的short元素第一次出现的位置
262 * @param arr 给定的short 数组
263 * @param seek 要查询的short 元素
264 * @return 如果找到元素,返回元素的索引;如果未找到元素,返回-1
265 */
266 public static int firstIndexOf(short[] arr,short seek){
267 for (int i = 0; i < arr.length; i++) {
268 if (arr[i]==seek){
269 return i;
270 }
271 }
272 return -1;
273
274 }
275
276 /**
277 * 在给定的long数组中查询指定的long元素第一次出现的位置
278 * @param arr 给定的long 数组
279 * @param seek 要查询的long 元素
280 * @return 如果找到元素,返回元素的索引;如果未找到元素,返回-1
281 */
282 public static int firstIndexOf(long[] arr,long seek){
283 for (int i = 0; i < arr.length; i++) {
284 if (arr[i]==seek){
285 return i;
286 }
287 }
288 return -1;
289
290 }
291
292 /**
293 * 在给定的float数组中查询指定的float元素第一次出现的位置
294 * @param arr 给定的float 数组
295 * @param seek 要查询的float 元素
296 * @return 如果找到元素,返回元素的索引;如果未找到元素,返回-1
297 */
298 public static int firstIndexOf(float[] arr,float seek){
299 for (int i = 0; i < arr.length; i++) {
300 if (arr[i]==seek){
301 return i;
302 }
303 }
304 return -1;
305
306 }
307
308 /**
309 * 在给定的double数组中查询指定的double元素第一次出现的位置
310 * @param arr 给定的double 数组
311 * @param seek 要查询的double 元素
312 * @return 如果找到元素,返回元素的索引;如果未找到元素,返回-1
313 */
314 public static int firstIndexOf(double[] arr,double seek){
315 for (int i = 0; i < arr.length; i++) {
316 if (arr[i]==seek){
317 return i;
318 }
319 }
320 return -1;
321
322 }
323
324 /**
325 * 在给定的char数组中查询指定的char元素第一次出现的位置
326 * @param arr 给定的char 数组
327 * @param seek 要查询的char 元素
328 * @return 如果找到元素,返回元素的索引;如果未找到元素,返回-1
329 */
330 public static int firstIndexOf(char[] arr,char seek){
331 for (int i = 0; i < arr.length; i++) {
332 if (arr[i]==seek){
333 return i;
334 }
335 }
336 return -1;
337
338 }
339
340 public static int firstIndexOf(String[] arr,String seek){
341 for (int i = 0; i < arr.length; i++) {
342 if (seek.equals(arr[i])){
343 return i;
344 }
345
346 }
347 return -1;
348 }
349
350 /**
351 * 判断给定的int数组是否包含指定的int元素
352 * @param arr 给定的int 数组
353 * @param seek 给定的int 元素
354 * @return 数组中含有该元素返回true,否则返回false
355 */
356 public static boolean isContain(int[] arr,int seek){
357 int index = firstIndexOf(arr,seek);
358 return index == -1 ? false : true;
359 }
360
361 /**
362 * 判断给定的byte数组是否包含指定的byte元素
363 * @param arr 给定的byte 数组
364 * @param seek 给定的byte 元素
365 * @return 数组中含有该元素返回true,否则返回false
366 */
367 public static boolean isContain(byte[] arr,byte seek){
368 int index = firstIndexOf(arr,seek);
369 return index == -1 ? false : true;
370 }
371
372 /**
373 * 判断给定的short数组是否包含指定的short元素
374 * @param arr 给定的short 数组
375 * @param seek 给定的short 元素
376 * @return 数组中含有该元素返回true,否则返回false
377 */
378 public static boolean isContain(short[] arr,short seek){
379 int index = firstIndexOf(arr,seek);
380 return index == -1 ? false : true;
381 }
382
383 /**
384 * 判断给定的long数组是否包含指定的long元素
385 * @param arr 给定的long 数组
386 * @param seek 给定的long 元素
387 * @return 数组中含有该元素返回true,否则返回false
388 */
389 public static boolean isContain(long[] arr,long seek){
390 int index = firstIndexOf(arr,seek);
391 return index == -1 ? false : true;
392 }
393
394 /**
395 * 判断给定的float数组是否包含指定的float元素
396 * @param arr 给定的float 数组
397 * @param seek 给定的float 元素
398 * @return 数组中含有该元素返回true,否则返回false
399 */
400 public static boolean isContain(float[] arr,float seek){
401 int index = firstIndexOf(arr,seek);
402 return index == -1 ? false : true;
403 }
404
405 /**
406 * 判断给定的double数组是否包含指定的double元素
407 * @param arr 给定的double 数组
408 * @param seek 给定的double 元素
409 * @return 数组中含有该元素返回true,否则返回false
410 */
411 public static boolean isContain(double[] arr,double seek){
412 int index = firstIndexOf(arr,seek);
413 return index == -1 ? false : true;
414 }
415
416 /**
417 * 判断给定的char数组是否包含指定的char元素
418 * @param arr 给定的char 数组
419 * @param seek 给定的char 元素
420 * @return 数组中含有该元素返回true,否则返回false
421 */
422 public static boolean isContain(char[] arr,char seek){
423 int index = firstIndexOf(arr,seek);
424 return index == -1 ? false : true;
425 }
426
427 /**
428 * 判断给定的String数组是否包含指定的String元素
429 * @param arr 给定的String 数组
430 * @param seek 给定的String 元素
431 * @return 数组中含有该元素返回true,否则返回false
432 */
433 public static boolean isContain(String[] arr,String seek){
434 int index = firstIndexOf(arr,seek);
435 return index == -1 ? false : true;
436 }
437
438
439 /**
440 * 判断给定int数组中包含指定int元素的数量
441 * @param arr 给定的int 数组
442 * @param seek 指定的int 元素
443 * @return 返回数组中的指定元素出现的个数
444 */
445 public static int containTimes(int[] arr,int seek){
446 int count = 0;
447 for (int i = 0; i < arr.length; i++) {
448 if (arr[i]==seek){
449 count++;
450 }
451 }
452 return count;
453 }
454
455 /**
456 * 判断给定byte数组中包含指定byte元素的数量
457 * @param arr 给定的byte 数组
458 * @param seek 指定的byte 元素
459 * @return 返回数组中的指定元素出现的个数
460 */
461 public static int containTimes(byte[] arr,byte seek){
462 int count = 0;
463 for (int i = 0; i < arr.length; i++) {
464 if (arr[i]==seek){
465 count++;
466 }
467 }
468 return count;
469 }
470
471 /**
472 * 判断给定short数组中包含指定short元素的数量
473 * @param arr 给定的short 数组
474 * @param seek 指定的short 元素
475 * @return 返回数组中的指定元素出现的个数
476 */
477 public static int containTimes(short[] arr,short seek){
478 int count = 0;
479 for (int i = 0; i < arr.length; i++) {
480 if (arr[i]==seek){
481 count++;
482 }
483 }
484 return count;
485 }
486
487 /**
488 * 判断给定long数组中包含指定long元素的数量
489 * @param arr 给定的long 数组
490 * @param seek 指定的long 元素
491 * @return 返回数组中的指定元素出现的个数
492 */
493 public static int containTimes(long[] arr,long seek){
494 int count = 0;
495 for (int i = 0; i < arr.length; i++) {
496 if (arr[i]==seek){
497 count++;
498 }
499 }
500 return count;
501 }
502
503 /**
504 * 判断给定float数组中包含指定float元素的数量
505 * @param arr 给定的float 数组
506 * @param seek 指定的float 元素
507 * @return 返回数组中的指定元素出现的个数
508 */
509 public static int containTimes(float[] arr,float seek){
510 int count = 0;
511 for (int i = 0; i < arr.length; i++) {
512 if (arr[i]==seek){
513 count++;
514 }
515 }
516 return count;
517 }
518
519 /**
520 * 判断给定double数组中包含指定double元素的数量
521 * @param arr 给定的double 数组
522 * @param seek 指定的double 元素
523 * @return 返回数组中的指定元素出现的个数
524 */
525 public static int containTimes(double[] arr,double seek){
526 int count = 0;
527 for (int i = 0; i < arr.length; i++) {
528 if (arr[i]==seek){
529 count++;
530 }
531 }
532 return count;
533 }
534
535 /**
536 * 判断给定char数组中包含指定char元素的数量
537 * @param arr 给定的char 数组
538 * @param seek 指定的char 元素
539 * @return 返回数组中的指定元素出现的个数
540 */
541 public static int containTimes(char[] arr,char seek){
542 int count = 0;
543 for (int i = 0; i < arr.length; i++) {
544 if (arr[i]==seek){
545 count++;
546 }
547 }
548 return count;
549 }
550
551 /**
552 * 判断给定String数组中包含指定String元素的数量
553 * @param arr 给定的String 数组
554 * @param seek 指定的String 元素
555 * @return 返回数组中的指定元素出现的个数
556 */
557 public static int containTimes(String[] arr,String seek){
558 int count = 0;
559 for (int i = 0; i < arr.length; i++) {
560 if (seek.equals(arr[i])){
561 count++;
562 }
563 }
564 return count;
565 }
566
567 /**
568 * 判断给定int数组石佛包含却仅包含一次给定int的元素
569 * @param arr 给定的int 数组
570 * @param seek 要查早的int 元素
571 * @return 包含且仅包含一次返回true 不包含或者包含多次返回false
572 */
573 public static boolean isOne(int[] arr,int seek){
574 int count = containTimes(arr,seek);
575 return count==1 ? true : false;
576 }
577
578 /**
579 * 判断给定byte数组石佛包含却仅包含一次给定byte的元素
580 * @param arr 给定的byte 数组
581 * @param seek 要查早的byte 元素
582 * @return 包含且仅包含一次返回true 不包含或者包含多次返回false
583 */
584 public static boolean isOne(byte[] arr,byte seek){
585 int count = containTimes(arr,seek);
586 return count==1 ? true : false;
587 }
588
589 /**
590 * 判断给定short数组石佛包含却仅包含一次给定short的元素
591 * @param arr 给定的short 数组
592 * @param seek 要查早的short 元素
593 * @return 包含且仅包含一次返回true 不包含或者包含多次返回false
594 */
595 public static boolean isOne(short[] arr,short seek){
596 int count = containTimes(arr,seek);
597 return count==1 ? true : false;
598 }
599
600 /**
601 * 判断给定long数组石佛包含却仅包含一次给定long的元素
602 * @param arr 给定的long 数组
603 * @param seek 要查早的long 元素
604 * @return 包含且仅包含一次返回true 不包含或者包含多次返回false
605 */
606 public static boolean isOne(long[] arr,long seek){
607 int count = containTimes(arr,seek);
608 return count==1 ? true : false;
609 }
610
611 /**
612 * 判断给定float数组石佛包含却仅包含一次给定float的元素
613 * @param arr 给定的float 数组
614 * @param seek 要查早的float 元素
615 * @return 包含且仅包含一次返回true 不包含或者包含多次返回false
616 */
617 public static boolean isOne(float[] arr,float seek){
618 int count = containTimes(arr,seek);
619 return count==1 ? true : false;
620 }
621
622 /**
623 * 判断给定double数组石佛包含却仅包含一次给定double的元素
624 * @param arr 给定的double 数组
625 * @param seek 要查早的double 元素
626 * @return 包含且仅包含一次返回double 不包含或者包含多次返回false
627 */
628 public static boolean isOne(double[] arr,double seek){
629 int count = containTimes(arr,seek);
630 return count==1 ? true : false;
631 }
632
633 /**
634 * 判断给定char数组石佛包含却仅包含一次给定char的元素
635 * @param arr 给定的char 数组
636 * @param seek 要查早的char 元素
637 * @return 包含且仅包含一次返回true 不包含或者包含多次返回false
638 */
639 public static boolean isOne(char[] arr,char seek){
640 int count = containTimes(arr,seek);
641 return count==1 ? true : false;
642 }
643
644 /**
645 * 判断给定String数组石佛包含却仅包含一次给定String的元素
646 * @param arr 给定的String 数组
647 * @param seek 要查早的String 元素
648 * @return 包含且仅包含一次返回true 不包含或者包含多次返回false
649 */
650 public static boolean isOne(String[] arr,String seek){
651 int count = containTimes(arr,seek);
652 return count==1 ? true : false;
653 }
654
655 }