Skip to content

Latest commit

 

History

History
72 lines (62 loc) · 3.23 KB

Java.md

File metadata and controls

72 lines (62 loc) · 3.23 KB

개요

  • 쓸만한 코드 조각 모아둠

  • Java의 경우 codotachrome plugin 를 사용해 저장함

    Codota's AI learns from existing Java code to help you build software faster and smarter. Codota uses learned code models to suggest relevant code. These suggestions save you time searching for references, and help prevent errors.

  • short if

    public int getForwardCoord(int randomVal) {
        return randomVal >=4? 1:0;
    }
  • split
        String str1 = "phone;;name;id;pwd";
        String word1 = str1.split(";")[0]; //phone
        String word2 = str1.split(";")[1]; //공백 "" 출력
        String word3 = str1.split(";")[3]; //pwd
         
        String[] words1 = str1.split(";", 0); // {"phone","name","id","pwd"}
        String[] words2 = str1.split(";", 2); // {"phone","name","id;pwd"}
  • List - initialze
// JDK 7
List<String> list = new ArrayList<>();
list.add("one");
list.add("two");
list.add("three");

//JDK 8
List<String> list = Stream.of("one", "two", "three").collect(Collectors.toList());

// JDK 9
List<String> list = List.of("one", "two", "three");
  • List - print element
// JDK 8 
list.forEach(System.out::println);
//with comma
String.join(",", list)
list.stream().collect(Collectors.joining(","))
//change Upper-case with Comma
list.stream().map(String::toUpperCase).collect(Collectors.joining(","));

// JDK 7
System.out.println(Arrays.toString(list.toArray()));