People forget. Especially if you write in various languages. If you read it before writing, you may make a lot of progress.
Mold | Description | range |
---|---|---|
byte | Integer 8 bits | -128~127 |
short | Integer 16 bits | -32,768~32,767 |
int | Integer 32 bits | -2,147,483,648~2,147,483,647 |
long | Integer 64 bits | -9,223,372,036,854,775,808~9,223,372,036,854,775,807 |
char | Unicode character 16 bits | \u0000~\uFFFF |
float | Floating point number 32 bits | (abridgement) |
double | Floating point number 64 bits | (abridgement) |
boolean | - | true, false |
5 + 2; //7 addition
5 - 2; //3 subtraction
5 * 2; //10 multiplication
5 / 2; //2 division
5 % 2; //1 remainder
y = ++x; //Prefix y= (x += 1);
y = x++; //Postfix y= x; x = x + 1;
x < y; //Less than
x <= y; //Less than
x >= y; //that's all
x > y; //Excess
x == y; //Equivalent
x != y; //Not equivalent
x && y; // AND
x || y; // OR
!x; // NOT
String str = "String"; //Initialization
str.length(); //length
str.subString(start, end); //start to end-Cut out 1
str1.equals(str2); //Equivalence judgment
str1.compareTo(str2); //Comparison
// str1 < str2 -> -1
// str1 == str2 -> 0
// str1 > str2 -> 1
char c = str.charAt(i); // String ->char i th character
char[] cs = str.toCharArray(); // String ->whole char
int i = Integer.parseInt(str); // int <- String
int i = (int) d; // int <- double
double d = Double.parseDouble(str); // double <- String
double d = (double) i; // double <- int
String s = String.valueOf(i); // String <- int
String s = String.valueOf(d); // String <- double
Math.max(2, 5); //5 larger
Math.min(2, 5); //2 smaller
Math.abs(-3); //3 Absolute value
Math.ceil(1.5); // 2.0 round up
Math.floor(1.5); // 1.0 truncation
Math.round(1.5); // 2.0 rounding
Math.pow(2, 10); //1024 power
Math.sqrt(2); // 1.414… Square root
Math.log10(1000); //3 Common logarithm
Math.PI //π pi
Math.E //e base of natural logarithm
I may write it soon.
if
if ( i > 0 ) {
;
} else if ( i < 0 ) {
;
} else {
;
}
for / for-each
for ( int i = 0; i < max; i++ ) {
;
}
for ( var : collection ) {
;
}
while / do-while
while ( i > 0 ) {
;
}
do {
;
} while ( i > 0 );
switch
switch ( i ) {
case 0:
;
break;
case 1:
;
break;
default:
;
}
//Initialization
int[] num = new int[10];
Arrays.fill(num, 0);
//Deep copy deep copy
String[] copySrc = new String[10]; //Original
String[] copyDst = new String[10]; //Copy to
copyDst = Arrays.copyOf(copySrc, copySrc.length);
//Initialization
int[][] num = new int[10][10];
for (int i = 0; i < num.length; i++) {
Arrays.fill(num[i], 0);
}
//Deep copy
String[][] copySrc = new String[10][10]; //Original
String[][] copyDst = new String[10][10]; //Copy to
for (int i = 0; i < copySrc.length; i++) {
copyDst[i] = Arrays.copyOf(copySrc[i], copySrc[i].length);
}
//Initialization
List<String> list = new ArrayList<String>();
//Manipulation by object
list.add(str); //add to
list.remove(str); //Delete
list.indexOf(str); //Get index
list.contains(str); //Existence check
//Operation by index
list.get(i); //Get i th
list.set(i, str); //Replace i th
//Initialization
// key -> int
// value -> String
HashMap<Integer, String> hMap = new HashMap<Integer, String>();
hMap.put(i, str); //add to
hMap.get(i); //Get
hMap.containsKey(i); //Existence check
PriorityQueue<Integer> pQueue = new PriorityQueue<Integer>();
pQueue.offer(i); //add to
pQueue.peek(i); //Get (do not remove from queue)
pQueue.poll(i); //Get (remove from queue)
Recommended Posts