Java creates a sub thread to start execution immediately Author: Chuwen Time: 2019-11-23 Classification: Java comment ```java public class InvokeRun extends Thread { private int i; @Override public void run() { for(; i<100; i++){ System.out.println("["+Thread.currentThread().getName()+"]\t"+i); } } public static void main(String[] args) throws Exception{ for(int i=0; i<100; i++){ System.out.println(Thread.currentThread().getName()+"\t"+i); if(i == 20){ new InvokeRun().start(); new InvokeRun().start(); //Let the current main thread sleep for 1ms //It will execute another ready thread //In this way, the child thread can start execution immediately Thread.sleep(1); } } } } ```
JavaScript traverses document. querySelectorAll() Author: Chuwen Time: 2019-11-20 Classification: JavaScript comment #If you use 'forEach' to traverse, an error will be reported because it returns a 'NodeList' instead of an array` ``` document.querySelectorAll('input[type='selece']]').forEach(function() { }); ``` We can iterate through the following methods ``` const selects = document.querySelectorAll("input[name='select']"); [].forEach.call(selects, function(select) { console.log(select); }); ```
Label in Java: the role of outer Author: Chuwen Time: 2019-11-08 Classification: Java comment #Label >* Label * provides a method to control a loop that cannot be implemented by a simple break statement. When a break is encountered in a loop statement, it will terminate regardless of other control variables. >But what happens when you want to exit a loop nested in several layers? >The normal 'break' only exits a loop. You can mark which statement you want to exit with a label. ``` char a; outer: //this is the label for the outer loop for(int i=0;i<10;i++) { for(int j=0;j<10;j++) { a=(char)System.in.read(); if(a=='b') break outer; if(a=='c') continue outer; } } ``` >In this example, the loop accepts 100 input characters from the keyboard. When the "b" character is entered, the 'break outer' statement will end the double loop. Note: The 'continue outer' statement tells the computer to * exit the current loop * and * * continue executing the 'outer loop' * *. Example 2: >Find prime number between 100-200 ``` System. out. println ("100~200 prime numbers"); int n = 0; outer: for (int i=101; i<200; i+=2){ for (int j = 2; j<i; j++){ if(i%j == 0) continue outer;// End this outer cycle } System.out.print(" "+i);;// Show prime numbers n++;// Calculate the number of prime numbers if(n<10) continue;// No line break if less than 10 System.out.println(); n = 0;// Reset the number of prime numbers } ``` --- Reprinted from: http://blog.sina.com.cn/s/blog_6f8bd746010136yr.html
[Official] Download address of domestic Android Studio Author: Chuwen Time: 2019-11-08 Classification: Chatter comment Link: https://developer.android.google.cn/studio