java.lang.string.split

The split method splits a string into substrings and returns the result as an array of strings.

StringObj. Split ([separator, [limit]])

StringObj Mandatory. The String or literal to be decomposed. This object is not modified by the split method.

Separator Optional. A string or regular expression object that identifies whether one or more characters are used to separate strings. If omitted, returns a single element array containing the entire string.

Limit Is optional. This value is used to limit the number of elements in the returned array.

The result of the split method is an array of strings, which are split at every separator location in stingObj. Separator is not returned as part of any array element.

Example 1: public class SplitDemo {

public static String[] ss = new String[20];

public SplitDemo() {

String s = “The rain in Spain falls mainly in the plain.”; // Decompose at each space character. ss = s.split(” “); }

public static void main(String[] args) {

​ SplitDemo demo = new SplitDemo(); ​ for (int i = 0; i < ss.length; i++) ​ System.out.println(ss[i]); }

}

The rain in Spain falls mainly in The plain.

There are also some examples in blog.csdn.net/pengzonglu7…

Main class not found: package name incorrectly written main function not written

The difference between next() and nextLine() : Scanner is a Scanner. We take the data from the keyboard and store it in the cache for reading. It determines that the mark at the end of reading is a blank character. Spaces, carriage returns, tabs, etc.

The next() method reads whitespace and terminates;

NextLine () reads until the carriage return ends, which is “\r”;

So the output is finished before next() checks for Spaces in the preorder test.

The difference between:

1) Replace takes char and CharSequence arguments, which can be used to replace characters as well as strings.

2)replaceAll takes a regex, which is a regular expression based substitution. For example, replaceAll(“\d”, “*”) replaces all numeric characters in a string with asterisks.

Similarities:

If you want to replace only the first occurrence, you can use replaceFirst(). This method is also based on regular expressions, but unlike replaceAll(), only replaces the first occurrence of the string.

In addition, if the arguments used by replaceAll() and replaceFirst() are not based on regular expressions, they have the same effect as replace(), which also supports string operations;

One more note: the contents of the source string do not change after the substitution operation.

package com.atguigu.contact; import java.util.Scanner;

import java.lang.String; / / with Java. Util. Arrays; I don’t have to write it

public class Test { public static void main(String[] args) { String s = “Today is a good day”; String[] ss = new String[20]; ss=s.split(” “); for (int i =0; i<5; i++) { System.out.println(ss[i]); } Scanner input = new Scanner(System.in); String s1 = input.nextLine(); input.close(); s.replace(“a”,”b”); Println (s1.replaceAll(“a”, “b”)); system.out.println (s1.replaceAll(“a”, “b”));

}
Copy the code

}

Postfix expression

Rule: iterate over each number and symbol of the expression from left to right. If it encounters a number, it will be pushed onto the stack. If it encounters a symbol, the two numbers at the top of the stack will be pushed off the stack and the operation results will be pushed onto the stack until the final result is obtained.

9, 3, 1-3*+ 10, 2/+ = 20 imagine that you used to do addition and subtraction from front to back, and now you’re doing it backwards

A & 1 is the same thing as A % 2 but it’s A little bit more cool to use the ampersand and use 1111 for example

The range of BigInteger numbers is much larger than that of Integer and Long numbers. It supports integers of arbitrary precision, which means that the BigInteger type can accurately represent any Integer value without losing any information in an operation.

char[] ch = s.toCharArray();

String s= "hello"; char[] ch = s.toCharArray(); // for (char c:ch) { System.out.println(c); CharAt (I) = charAt(ICopy the code

Import java.math.bigINTEGER before using BigInteger

public void testBasic() { BigInteger a = new BigInteger(“13”); BigInteger b = new BigInteger(“4”); int n = 3;

//1. Add BigInteger bigNum1 = a.dd (b); BigInteger bigNum2 = a.subtract(b); //9 //3. Multiply BigInteger bigNum3 = a.ultiply (b); BigInteger bigNum4 = a.devide (b); ArithmeticException("BigInteger: Modulus not positive") BigInteger bigNum5 = a.m. OD (b); BigInteger bigNum6 = a.remainder(b); Sq. ArithmeticException("Negative exponent") BigInteger bigNum7 = a.popow (n); BigInteger bigNum8 = a.bs (); BigInteger bigNum9 = a.negate(); / / - 13}Copy the code

The method remainder of type BigInteger does not work for parameter int but POw (int) does

Blue bridge cup: divisible by a number depends on the remainder so %

class Boy { int age; } class Girl { int age; public int compare(Boy boy) { return Math.max(age, boy.age ); // You don’t have to create a new class to put this method in}}

package com.atguigu.contact; import java.util.Scanner;

import java.lang.String; / / with Java. Util. Arrays; The same import Java. Math. BigInteger;

public class Test { public static void main(String[] args) { Customer person = new Customer(“Jane”,”Smith”); Person. SetAccount (1000,0.0123, 2000100960200); person.getAccount();

}
Copy the code

} class Account { private int id; private double balance; private double annualInterestRate; public int getId() { return id; } public void setId(int id) { this.id = id; } public double getBalance() { return balance; } public void setBalance(double balance) { this.balance = balance; } public double getAnnualInterestRate() { return annualInterestRate; } public void setAnnualInterestRate(double annualInterestRate) { this.annualInterestRate = annualInterestRate; } public void withdraw(double amount) {if(balance>amount) {system.out.println (” withdraw money “); balance-=amount; }else { balance-=amount; System.out.println(” insufficient balance, please recharge “); }

}
public void deposit(int money)
{
	balance+=money;
}
Copy the code

} class Customer { private String firstName; private String lastName; private Account account; This. account=account(parameter) public Customer(String f,String l) {f=firstName; l=lastName; } public String getFirstName() { return firstName; } public String getLastName() { return lastName;

} public void setAccount(int id,double annual,int balance,int cun,double qu, double quqian) { account = new Account(); // Account. id=id; / /?????? Because you can't call account.setid (id); // don't use new ???? account.setAnnualInterestRate(annual); account.setBalance(balance); account.deposit(cun); account.withdraw(qu); account.withdraw(quqian); } public void getAccount () / / here you can modify to public Account getAccount () to return the Account at last call person. GetAccount () id { System.out.println(account.getAnnualInterestRate()); System.out.println(account.getBalance()); System.out.println(account.getId()); }Copy the code

}

3.7

Next time after private all properties directly shortcut to create get set

package com.atguigu.contact;

class Test { public static void main(String[] args) { Bank bank = new Bank(); bank.addCustomer(“Jane”,”Smith”); Account one = new Account(2000); bank.getCustomer(0).setAccount(one); Bank.getcustomer (0).getAccount().withdraw(500); System.out.println(bank.getCustomer(0).getAccount().getBalance()); System.out.println(bank.getCustomer(0).getLastName()); } } class Account { private double balance; public Account(double balance) { this.balance=balance; } public double getBalance() { return balance; } public void deposit(double amt) { balance+=amt; } public void withdraw(double amt) {if(amt>balance) {system.out.println ();} public void withdraw(double amt) {if(balance >balance) {system.out.println (); }else { balance-=amt; } } } class Customer { private String firstName; private String lastName; private Account account; This. account=account(parameter) public Customer(String f,String l) {f=firstName; // l=lastName; } public String getFirstName() { return firstName; } public String getLastName() { return lastName;

} public Account getAccount() { return account; } public void setAccount(Account Account) {this. Account = Account; // Set the reason for the above private Account}Copy the code

} customer {private customer [] customer=new customer [100]; Private int numberOfCustomer=0; public Bank() {

} public void addCustomer(String f,String l) { Customer cust = new Customer(f,l); //customer=new Customer[4]; // Imagine other class constructors used this way in mainCopy the code

// customer[3].getFirstName()=f; // customer[3].getLastName()=l; //customer[3]= new Customer(f,l); Customer [numberOfCustomer]=cust; numberOfCustomer++; } public int getNumberOfCustomer() { return numberOfCustomer; } public Customer getCustomer(int index) { return customer[index]; }}

Package:

1 Implement the management of classes

All package names are lowercase

3 Each time is a layer of directory

4 You can name interfaces and classes () with the same name in different packages because the directories are different

Java.lang Adds the lang table language by default

You don’t have to learn AWT Swing

MVC M: the model layer has a lot of data to call V: the view layer, such as the contacts on wechat and the circle of friends, has patterns of length and width. C: The control layer loads the data in M into V. In fact, everything except M and V seems to be C