-------
android培训、java培训、期待与您交流! ----------
------------------------Arrays工具类--------------------------------------------------------------------------------------
-
-
-
-
-
-
-
-
- public class ArraysDemo {
- public static void main(String[] args) {
-
- int[] arr = { 45, 37, 94, 82, 63 };
-
-
-
- String s = Arrays.toString(arr);
- System.out.println("s:" + s);
-
-
- Arrays.sort(arr);
- System.out.println("arr:" + Arrays.toString(arr));
-
-
- int index = Arrays.binarySearch(arr, 82);
- System.out.println("index:" + index);
- }
-
- public static String arrayToString(int[] arr) {
- StringBuilder sb = new StringBuilder();
- sb.append("[");
-
- for (int x = 0; x < arr.length; x++) {
- if (x == arr.length - 1) {
- sb.append(arr[x]);
- } else {
- sb.append(arr[x]).append(",");
- }
- }
- sb.append("]");
- return sb.toString();
- }
- }
-------------------------------Collections工具类----------------------------------------------------------------------------
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public class CollectionsDemo {
- public static void main(String[] args) {
-
- List<Integer> list = new ArrayList<Integer>();
-
-
-
-
-
- list.add(9);
- list.add(5);
- list.add(4);
- list.add(6);
- list.add(7);
- list.add(8);
- list.add(3);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Collections.shuffle(list);
-
- System.out.println("list:" + list);
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public class CardDemo {
- public static void main(String[] args) {
-
-
- String[] colors = { "黑桃", "红桃", "梅花", "方块" };
-
- String[] cards = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10",
- "J", "Q", "K" };
-
- ArrayList<String> array = new ArrayList<String>();
-
- for (int x = 0; x < colors.length; x++) {
- for (int y = 0; y < cards.length; y++) {
-
- array.add(colors[x].concat(cards[y]));
- }
- }
-
- array.add("大王");
- array.add("小王");
-
-
- Collections.shuffle(array);
-
- System.out.println(array);
- }
- }
-----------------------------------System系统类--------------------------------------------------------------------------------
-
-
-
-
-
-
-
- public class SysetmDemo {
- public static void main(String[] args) {
-
-
-
-
-
-
-
-
-
-
-
- long start = System.currentTimeMillis();
-
-
-
-
-
- StringBuilder sb = new StringBuilder();
- for (int x = 0; x < 100000; x++) {
- sb.append(x);
- }
-
- long end = System.currentTimeMillis();
- System.out.println("time:" + (end - start) + "毫秒");
- }
- }
-------------------------------Runtime类----------------------------------------------------------------------------------
-
-
-
-
- public class RuntimeDemo {
- public static void main(String[] args) {
-
- Runtime r = Runtime.getRuntime();
-
-
-
- try {
-
- r.exec("winmine");
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
|