Make efforts eveyday

Q & A questions

1. For strings

String s1=new String("ok");

String s2=new String("ok");

Write the value of the following expression

s1==s2 false

s1.equals(s2)  true

2. For strings

String s1=new String("I love you zhht");

String s2=s1.replaceAll("love","hate");

Write System.out.printf("%s,%s",s1,s2) Result

3.String Classes and StringBuffer What's the difference between classes

String Class cannot modify characters ,StringBuffer Class can be modified

4. about StringBuffer character string

StringBuffer str-new StringBuffer("abcdefg");

str=str.delete(2,4);

Write out the output str result

abefg

5.StringTokenizer What is the main purpose of class ? What are the important methods of this class ?

Split string

Important method hasMoreTokens Determine if there is a next iteration object

nextToken return String Type object

6. The following System.out.printf What is the output result

String s=new String("we,go,to,school");

StringTokenizer token=new StringTokenizer(s,",");

String word=token.nextToken();

int n=token.countTokens();

System.out.printf("%s,%d",word,n);

we,3

7.Matcher Object's find() Methods and lookingAt() How is the method different ?

lookingAt Match from the beginning

find It's from start Position matching

8. Regular expressions [123] What does it mean ?

123 Any one of

9. Writing and patterns “A[135]{2}” Four matching strings

A11 A13 A15 A35

10. I don't know which characters match “boy\\w{3}”

A.boy111 B.boy!@# C.boyweo D.boyboyboyboy

C

Homework questions

1. Write an application , The user enters a line of string from the keyboard , The program outputs the string and pattern “[24680]A[13579]{2}” Matching string

public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
Pattern p=Pattern.compile("[24680]A[13579]{2}");
Matcher m=p.matcher(str);
while(m.find()) {
System.out.println(m.group());
}
}

Screenshot :

2. Write an application , The user outputs a string of numbers from the keyboard , The program just outputs all the numeric characters of the string

public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
Pattern p=Pattern.compile("\\d+");
Matcher m=p.matcher(str);
while(m.find()) {
System.out.println(m.group());
}
}

Screenshot :

JavaSE exercises Chapter six More articles on strings and regular expressions

  1. Zero basis to learn Python-------- The first 5 Chapter Strings and regular expressions

    The first 5 Chapter Strings and regular expressions 5.1 String common operations stay Python Development process , In order to achieve a function , Special handling of certain strings is often required , Such as splicing string . Intercepting string . Format string, etc . The following will be true of Python Commonly used ...

  2. C# Advanced programming 9- The first 9 Chapter Strings and regular expressions

    Strings and regular expressions String class String Class objects are immutable , about String An object's reassignment essentially recreates a String Object and assign a new value to it , Its method ToString The performance improvement is not very obvious ...

  3. Python Core programming exercises after class - Chapter six

    1. character string , string Is there a string method or function in the module that can help me identify whether a string is part of another large string ? str1 = 'abcdefghijklmnopqrstuv' print st ...

  4. JavaSE exercises Chapter vii. Common practical class

    Q & A questions 1. How to instantiate a Calendar object ? Calendar ca=Calendar.getInstance(); 2.Calendar Object call set(1949,9,1) What's the date of the month and year ? ...

  5. JavaSE exercises Chapter four Classes and objects

    Q & A questions : 1. When declaring a class , What habits should class names follow ? 1. Same as file name 2. title case 2. Which two kinds of important members are there in the content of class body ? 1. Member variables 2. Method 3. Can instance methods manipulate class variables ? Can class methods manipulate instance variables ? ...

  6. javaSE exercises The third chapter Operator 、 Expressions and statements

    Question and answer : 1. The following System.out.printf What is the result ? int a=100,x,y; x=++a; y=a--; System.out.printf("%d,%d,%d" ...

  7. Python Programming fast Chapter 6 Summary

    Chapter six String manipulation Preface This chapter talks about Python Knowledge of string types in . String related operators , Methods, etc. . Processing strings : Writing string . Print . Access to knowledge Original string Format :r'string' effect : stay ...

  8. 《Python Programming core 》 Chapter six Sequence - After-school exercises

    After-school exercises 6–1. character string .string Is there a string method or function in the module that can help me identify whether a string is part of another large string ? answer : Membership operators (in.not in) import string ...

  9. python course Chapter 16 、 Regular expressions

    Chapter 16 . Regular expressions 1)    Match multiple expressions mark   re1|re2 explain   Match regular expression re1 or re2 give an example   foo|bar  matching   foo, bar mark   {N} explain   Match the front out ...

Random recommendation

  1. ASP.NETMVC Is it really easy to customize error pages ?

    Note: The first half of the article is translated from http://benfoster.io/blog/aspnet-mvc-custom-error-pages , If you are in a hurry, you can look at the summary directly ~ If you're setting up asp.net mvc since ...

  2. [AngularJS] Best Practise - Controller

    ControllerAs: Use thecontrollerAs syntax always as it aids in nested scoping and controller instance ...

  3. JSON understand

    from : http://blog.csdn.net/qyf_5445/article/details/8635578 (json A very comprehensive understanding of ) http://www.cnblogs.com/haitao ...

  4. transplant MQTT broker mosquitto To omapl138

    summary This transplant uses chuanglong's TL138-EVM Development board , be based on TI Of MCSDK development environment . The specific upper computer system is Ubuntu 12.04-32bit, The software environment is based on chuanglong's user manual . In order to transplant in 13 ...

  5. HDU 1874 Unimpeded project continued 【Floyd Algorithm implementation 】

    Unimpeded project continued Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  6. C++ And Simple Gobang AI Program

    I am a freshman , Boring in winter vacation , Try it ( I didn't expect to finish it ), Yes C++ Simple Gobang program of , Happy .      Here is the effect :      One . First of all, let's talk about the general idea .            The foundation of the realization of Gobang :  ...

  7. A set of code applet &Web&Native The exploration of operation 04—— Data update

    Continued above : A set of code applet &Web&Native The exploration of operation 03 Corresponding Git Please refer to :https://github.com/yexiaochai/wxdemo/tree/master/m ...

  8. The fast Fourier transform FFT& Number theory transformation NTT

    Related knowledge Functions in the time domain f(t) After Fourier transform (Fourier Transform) Become... In the frequency domain F(w), That is to say, add some sinusoids with different frequencies The signal in time domain is obtained by weight superposition . \[ F(\omega)=\m ...

  9. Golang- course

    http://www.runoob.com/go/go-environment.html https://www.pythonav.cn/

  10. js Code click triggers events

    js Trigger button click event function load(){ // The following two methods have the same effect document.getElementById("target").onclick(); do ...