forked from ShashwatAwasthi04/Coding-Questions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSome Random java fun.txt
More file actions
65 lines (31 loc) · 1.21 KB
/
Copy pathSome Random java fun.txt
File metadata and controls
65 lines (31 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Reverse an Array in Java
Collections.reverse(Arrays.asList(array));
Sum a List of Numbers
IntStream.range(1, 1000).sum();
2)Check if a String contains at least one of the given keyword
List<String> wordList = Arrays.asList("java", "feature", "love");
String str = "Dummy text. Java 8 has powerful features";
System.out.println(wordList.stream().anyMatch(str::contains));
3)Copy file from One location to another
Files.copy(Paths.get("/data/text/file.txt"),Paths.get
4)Binary representation of number n
Integer.toBinaryString(int n);
5)Executing a commented Code
// \u000d System.out.println("comment executed");
6)Make a collection unmodifiable
public static final Collection secret=
Collections.unmodifiableCollection(Arrays.asList("Jimmy","Carter","JOhn") );
7)Faster Multiplication and Division
n = n << 1; // Multiply n with 2
n = n >> 1; // Divide n by 2
8)Sort an Array
Arrays.sort(arrayReference);
9)Input a character using Scanner
char c = sccanner.next().charAt(0);
Let double K = Math.log10(N);
now K = K - Math.floor(K);
int X = (int)Math.pow(10, K);
X will be the most significant digit.
No. of digits in N = Math.floor(Math.log10(N)) + 1;
Splitting String to words
use String.split(" ");