Explanation of common java string processing methods

Source: Internet
Author: User

Java code

  1. /* @ Src http://eric-619.javaeye.com/blog/693636
  2. * Common methods in the java. lang. String class: (common methods for String processing)
  3. * 1. The parameters are not strict; 2. Strings support regular expressions.
  4. *
  5. * 1. length ():
  6. * Specify the length of a string;
  7. *
  8. * 2. substring (int begin)
  9. * Substring (int beginindex, int endindex)
  10. * Substring (). The parameter starts from scratch;
  11. *
  12. * 3. split (String s1)
  13. * Split (String s2, int I)
  14. *
  15. * 4. startsWith (String s1)
  16. * StartsWith (String s2, int I)
  17. * EndsWith (String s3)
  18. *
  19. * 5. replace (String sb, String st)
  20. * ReplaceAll (String sb, String st)
  21. *
  22. */
  23. Public ClassTestString {
  24. Public Static VoidMain (String [] args ){
  25. NewTestString (). testLength ();
  26. NewTestString (). testSubstring ();
  27. NewTestString (). testSplit ();
  28. NewTestString (). testStartsendsWith ();
  29. NewTestString (). testReplaceAll ();
  30. }
  31. // 1. length ():
  32. Public VoidTestLength (){
  33. String slen = "abc ";
  34. String slenn =NewString ("abcdefg ");
  35. IntI = slen. length ();
  36. IntK = slenn. length ();
  37. System. out. println (I );
  38. System. out. println (k );
  39. System. out. println ("-----------------------------");
  40. }
  41. // 2. substring (int begin), substring (int beginindex, int endindex)
  42. // Note: The number of strings starts from zero.
  43. Public VoidTestSubstring (){
  44. String se =NewString ("abcdefgh ");
  45. String sea = se. substring (3 );
  46. String seaa = se. substring (3, 5 );
  47. System. out. println (sea );
  48. System. out. println (seaa );
  49. System. out.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.