Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
329 views
in Technique[技术] by (71.8m points)

java.util.scanner - Explain this line written in JAVA

In HACKERRANK this line of code occurs very frequently. I think this is to skip whitespaces but what does that " u2028u2029u0085" thing mean

 scanner.skip("(
|[

u2028u2029u0085])?");
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Scanner.skip skips a input which matches the pattern, here the pattern is :-

( |[ u2028u2029u0085])?

  • ? matches exactly zero or one of the previous character.
  • | Alternative
  • [] Matches single character present in
  • matches a carriage return
  • newline

  • u2028 matches the character with index 2018 base 16(8232 base 10 or 20050 base 8) case sensitive

  • u2029 matches the character with index 2029 base 16(8233 base 10 or 20051 base 8) case sensitive
  • u0085 matches the character with index 85 base 16(133 base 10 or 205 base 8) case sensitive

1st Alternative

  • matches a carriage return (ASCII 13)
  • matches a line-feed (newline) character (ASCII 10)

2nd Alternative [ u2028u2029u0085]

  • Match a single character present in the list below [ u2028u2029u0085]
  • matches a line-feed (newline) character (ASCII 10)
  • matches a carriage return (ASCII 13)
  • u2028 matches the character with index 202816 (823210 or 200508) literally (case sensitive) LINE SEPARATOR
  • u2029 matches the character with index 202916 (823310 or 200518) literally (case sensitive) PARAGRAPH SEPARATOR
  • u0085 matches the character with index 8516 (13310 or 2058) literally (case sensitive) NEXT LINE

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...