Java basic syntax + α trap

if

boolean b = false;

if (b = true){
    System.out.println("true");
}else{
    System.out.println("false");
}

switch

while

int i = 0;
while(i++ < 10);{
    System.out.println("a");
}

Is only incremented by i.

break Only loops (for, while) and switches can be used

constructor

class Orange{
    int i;

    Orange(){
        this(this.i);
    } 

    Orange(int i){}
}

Initialization of arrays and variable containers (StringBuilder, List)

	public static void main(String[] args) {
		String ary[] = new String[3];
		System.out.println(ary.length);  // => 3
		
		StringBuilder sb = new StringBuilder(3);
		System.out.println(sb.length());  // => 0
		
		List<String> list = new ArrayList<String>(3);
		System.out.println(list.size());  // => 0
	}


Generics


public interface Portable<Integer>{
    public void handCarry(Integer weight);
}

When using a lambda expression

NG pattern

Portable p = (Integer w) -> System.out.println(w);

OK pattern


Portable<Integer> p = (Integer w) -> System.out.println(n);

Portable p = w -> System.out.println(w);

The order is maintained when using Stream's paralell () and reduce () in combination.


System.out.println(Stream.of("a", "b", "c", "d").parallel().reduce((x,y)->x+"-"+y).get());  // =>Always a-b-c-d

Stream.of("a", "b", "c", "d").parallel().forEach(System.out::print);  // =>In no particular order a, b, c,d is output

Recommended Posts

Java basic syntax + α trap
Java control syntax
Java control syntax
Java basic grammar
Java basic grammar
Java basic knowledge 1
[Java] Basic structure
[Java] [Basic] Glossary
Java basic grammar
Java basic grammar
Java exercises [Basic]
Kotlin's simple basic syntax
java basic knowledge memo
[Java] Data type ①-Basic type
ruby basic syntax memo
[Java] Control syntax notes
Java basic date manipulation
Java basic naming conventions
Java learning memo (basic)
[Java] Basic method notes
Java basic data types
Basic Java OOps concepts
Java basic learning content 7 (exception)
Basic Authentication with Java 11 HttpClient
[Java] Basic statement for beginners
Java basic learning content 5 (modifier)
[Java] Thymeleaf Basic (Spring Boot)
Implement Basic authentication in Java
Java study # 7 (branch syntax type)
[Java] Summary of control syntax
Java Basic Learning Content 8 (Java API)
[Beginner] Java basic "array" description
Java basic learning content 4 (repetition)
[Java] Basic terms in programming
[Java] Object-oriented syntax --class method / argument
[Java] Basic types and instruction notes
Java basic learning content 3 (operator / ternary operator)
Basic data types and reference types (Java)
Java basic learning content 9 (lambda expression)
Basic usage of java Optional Part 1
Java basic learning content 2 (array / ArrayList)
Reading and writing Java basic files
Basic processing flow of java Stream
Java basic data types and reference types
[Basic knowledge of Java] Scope of variables
[Java] Exception types and basic processing
Basic structure of Java source code
Java and Swift comparison (2) Basic type / arithmetic expression / control syntax / function definition