1.Basic type
1.1 Storage space
byte 1 byte | |
short 2 bytes int 4 bytes long 8 bytes | |
float 4 bytes double 8 bytes | |
char 2 bytes | |
boolean 1 byte |
##1.2.1 char a = '\u0041' can represent a Chinese character, based on the original Unicode specification
1.2.2 char a = 99
a can be directly compared:
char a = 99; if (a < 'z' && a > 'a') { System.out.println(a); }
2. Operator
2.1Ternary operator
Boolean Expression? Expression 1: Expression 2
Exercise:
When x>0: sgn(x)=1;
When x=0: sgn(x )=0;
When x
Input x and output the value of sgn(x).
public static void function04(){ System.out.println("请输入x的值:"); Scanner scan = new Scanner(System.in); int x = scan.nextInt(); System.out.println("sgn(x)=" + (0==x?0:(x>0?1:-1))); }
2.2 Operator precedence
'{}' > '++' > '(强制类型转换)' > '/' > '+' > '<<' > '>=' > '==' > '&' > '^' > '|' > '&&' > '||' > '?:' > '='
2.3 "equals()" and "=="
equals
Note: the equals method cannot act on Variables of basic data types.
If the equals method is not rewritten, the address of the object pointed to by the reference type variable is compared;
If classes such as String and Date have rewritten the equals method , what is compared is the content of the pointed object.
==
If it acts on a variable of a basic data type, directly compare whether the "value" stored in it is equal;
If it acts on a variable of a reference type, then What is compared is the address of the pointed object.
3.String
/** * 1:输出字符串"HelloWorld"的字符串长度 * 2:输出"HelloWorld"中"o"的位置 * 3:输出"HelloWorld"中从下标5出开始第一次出现"o"的位置 * 4:截取"HelloWorld"中的"Hello"并输出 * 5:截取"HelloWorld"中的"World"并输出 * 6:将字符串" Hello "中两边的空白去除后输出 * 7:输出"HelloWorld"中第6个字符"W" * 8:输出"HelloWorld"是否是以"h"开头和"ld"结尾的。 * 9:将"HelloWorld"分别转换为全大写和全小写并输出。 */ public class Test01 { public static void main(String[] args) { String str = "HelloWorld"; test1(str); } public static void test1(String str){ System.out.println(str.length()); } public static void test2(String str){ System.out.println(str.indexOf('o')); } public static void test3(String str){ System.out.println(str.indexOf('o', 5)); } public static void test4(String str){ System.out.println(str.substring(0,5));//substring()内取右不取左 } public static void test5(String str){ System.out.println(str.substring(5)); } public static void test6(String str){ System.out.println(str.trim()); } public static void test7(String str){ System.out.println(str.charAt(5)); } public static void test8(String str){ System.out.println(str.startsWith("h")+"\n"+str.endsWith("ld")); } public static void test9(String str){ System.out.println(str.toLowerCase()+"\n"+str.toUpperCase()); } }
4.Array
4.1 Creation and writing method
int[] arr = new int[10]; //初始化 int[] arr = {1,2,3,4,5}; //初始化并赋值 int[] arr1 = new int[] {1,2,3,4,5};
4.2 Array operation code
//将Array转化成Set集合 Set<String> set = new HashSet<String>(Arrays.asList(stringArray)); System.out.println(set); //[d, e, b, c, a] //数组翻转 int[] intArray = { 1, 2, 3, 4, 5 }; ArrayUtils.reverse(intArray); System.out.println(Arrays.toString(intArray)); //[5, 4, 3, 2, 1] //从数组中移除一个元素 int[] intArray = { 1, 2, 3, 4, 5 }; int[] removed = ArrayUtils.removeElement(intArray, 3);//create a new array System.out.println(Arrays.toString(removed)); //将一个int值转化成byte数组 byte[] bytes = ByteBuffer.allocate(4).putInt(8).array(); for (byte t : bytes) { System.out.format("0x%x ", t); } //检查数组中是否包含某一个值 String[] stringArray = { "a", "b", "c", "d", "e" }; boolean b = Arrays.asList(stringArray).contains("a"); System.out.println(b); // true //连接两个数组 int[] intArray = { 1, 2, 3, 4, 5 }; int[] intArray2 = { 6, 7, 8, 9, 10 }; // Apache Commons Lang library int[] combinedIntArray = ArrayUtils.addAll(intArray, intArray2); //将数组中的元素以字符串的形式输出 String j = StringUtils.join(new String[] { "a", "b", "c" }, ", "); System.out.println(j);
The above is the detailed content of Development basics of Java development summary. For more information, please follow other related articles on the PHP Chinese website!

在使用Netty开发WebSocket服务器时,可能会遇到浏览器在尝试连接时未能正确处理服务器返回的401状态码的情况。 �...

Java compilation failed: Running window javac command cannot generate class file Many Java beginners will encounter this problem during the learning process: running window...

Discussing the hierarchical architecture problem in back-end development. In back-end development, common hierarchical architectures include controller, service and dao...

Packages and Directories in Java: The logic behind compiler errors In Java development, you often encounter problems with packages and directories. This article will explore Java in depth...

Leetcode ...

JWT and Session Choice: Tradeoffs under Dynamic Permission Changes Many Beginners on JWT and Session...

How to correctly configure apple-app-site-association file in Baota nginx? Recently, the company's iOS department sent an apple-app-site-association file and...

How to understand the classification and implementation methods of two consistency consensus algorithms? At the protocol level, there has been no new members in the selection of consistency algorithms for many years. ...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 English version
Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.