Java 填坑笔记一

2017-06-22  本文已影响0人  SherlockMoon
    @Test
    public void test() {        
        List<String> strings = new ArrayList<>();
        strings.add("hehe");
        for (String e: strings) {
            e = e.toUpperCase();
            e += "hehe";
        }
        for (String string : strings) {
            System.out.println(string);
        }
    }
   /*
    运行结果:
    hehe
   */
    @Test
    public void test() {        
        List<StringBuilder> strings = new ArrayList<>();
        strings.add(new StringBuilder("hehe"));
        for (StringBuilder e: strings) {
            e.append("hehe");
        }
        for (StringBuilder string : strings) {
            System.out.println(string);
        }
    }
   /*
    运行结果:
    hehehehe
   */
    @Test
    public void test() {        
        for (Integer integer = -129; integer <= 128; integer++) {
            Integer j = integer.intValue();
            if (integer != j)
                System.out.println(integer + " " + j);
        }
     }
  /*
    运行结果:
    -129 -129
    128 128
   */

    @Test
    public void test() {        
        Integer aInteger = 2;
        Integer bInteger = 2;
        Integer cInteger = 200;
        Integer dInteger = 200;
        System.out.println(aInteger == bInteger);
        System.out.println(cInteger == dInteger);
    }

  /*
    运行结果:
    true
    false
   */

   class Person {
        int age;
        String name;
        public Person(int age, String name) {
            this.age = age;
            this.name = name;
        }
        
        @Override
        public String toString() {
            return "age: " + String.valueOf(this.age) + ", name: " + name;
        }
    }
    
    @Test
    public void test() {        
        int a = 1;
        addOne(a);
        System.out.println(a);
        Person person = new Person(10, "child");
        addTwo(person);
        System.out.println(person);
    }

    private void addOne(int val) {
        val += 1;
    }
    
    private void addTwo(Person person) {
        person.age += 2;
    }

    /*
      运行结果:
      1
      age: 12, name: child
     */
上一篇 下一篇

猜你喜欢

热点阅读