If you are looking for software to use, go to Huajun Software Park! software release
Location: front pageTutorial strategyTutorialComputer software tutorials 20 mind-blowing...

20 Amazing One Lines of Java Code

Author: Huajun Information Date: 2023-11-13

java8 download 64 bit
java8 download 64-bit-v8.0.660.18 latest version

programming tools Storage size: 56.89MB Time: 2022-12-06

Software introduction: Java8 download 64-bit official version is a powerful Java language programming software. Download the latest 64-bit version of java8 to support multilingual programming...

Download now

Today I would like to share with you 20 amazing Java one-line codes to make your work easier. Let’s take a look!

1. Get the value of browser cookie

Use document.cookie to get the cookie value.

2. Convert RGB to Hexadecimal

3. Copy to clipboard
Use navigator.clipboard.writeText to easily copy any text to the clipboard.

4. Check if the date is valid
Use the following snippet to check if the date is valid.

5. Find the day of the year
Find a day in a date.

6. Capitalize the first letter of a string
Javascript does not have a built-in uppercase function, so we can use the following code.

7. Calculate the number of days between two days
Use the following code snippet to find the number of days between a given 2 days.

8. Clear all cookies
All cookies stored in a web page can be easily cleared by using document.cookie.
9. Generate random hex
Generate random hex using Math.random and padEnd properties.

10. Array deduplication
Duplicates can be easily removed using SetJavaScript. Super useful!

11. Get query parameters from URL
Easily query parameters of goole.com?search=easy&page=3 via window.location or original URL.
12. Get time in "hours, minutes and seconds" format from date
We can get the time in hour : minutes : seconds format from the date:

13. Confirm odd and even numbers
14. Find the average
Use the reduce method to find the average of multiple numbers.

15. Back to top
Use the window.scrollTo(0, 0) method to automatically return to the top. Set both x and y to 0.

16. Flip a string
Easily flip strings using split, reverse and join methods.

17. Check if array is empty
Simple code that checks if an array is empty, returning true or false.

18. Get the text selected by the user
Get the user-selected text using the built-in getSelection property.

19. Shuffle the array
Use the sort and random methods to shuffle arrays.

20. Detect if user is in dark mode
Use the following code to check if the user's device is in dark mode.

This tutorial is reproduced on the Internet. If there is any infringement, please contact us to delete it~~

Related articles