This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RateLimiterDemo { | |
public static void main(String[] args) { | |
RateLimiter limiter = new RateLimiterImpl(); | |
System.out.println("test1 " + limiter.accept("test1")); | |
System.out.println("test1 " +limiter.accept("test1")); | |
System.out.println("test1 " +limiter.accept("test1")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.learning; | |
import java.util.concurrent.locks.Lock; | |
import java.util.concurrent.locks.ReentrantLock; | |
public class ReentranceLockDemo { | |
final static Custom c= new Custom(); | |
public static void main(String[] args) throws InterruptedException { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// convinient methods | |
public HashMap getAddressMap() { | |
final String KEY="1"; | |
HashMap map = new HashMap(); | |
if(AdminAreaLevel1!=null) | |
map.put(AdminAreaLevel1.toLowerCase(), KEY); | |
if(AdminAreaLevel2!=null) | |
map.put(AdminAreaLevel2.toLowerCase(),KEY); | |
if(postcode!=null) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.learning; | |
import java.util.concurrent.CountDownLatch; | |
public class ThreadArray { | |
public static void main(String[] args) { | |
CountDownLatch latch = new CountDownLatch(10); | |
Thread[] t = new Thread[10]; | |
MyThread[] mt = new MyThread[10]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@FunctionalInterface //optional | |
interface MyInterface{ | |
public void myMethod(); | |
} | |
public class LambdaExpressionEx{ | |
public static void main(String args[]) | |
{ | |
int variable = 10; | |
//implemenmtation without lambda expression | |
MyInterface myInterface = new MyInterface(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
public class CE { | |
public static void main(String[] args) { | |
// NOTE: The following input values are used for testing your solution. | |
int[] array1A = {1, 3, 4, 6, 7, 9}; | |
int[] array2A = {1, 2, 4, 5, 9, 10}; | |
// commonElements(array1A, array2A) should return [1, 4, 9] (an array). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.HashMap; | |
public class MF { | |
public static void main(String[] args) { | |
// NOTE: The following input values are used for testing your solution. | |
// mostFrequent(array1) should return 1. | |
int[] array1 = {1, 3, 1, 3, 2, 1}; | |
// mostFrequent(array2) should return 3. | |
int[] array2 = {3, 3, 1, 3, 2, 1}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RotateByReversal { | |
public static void main(String[] args) { | |
int arr[] ={1,2,3,4,5,6,7}; | |
RotateByReversal rr = new RotateByReversal(); | |
rr.reverse(arr, 0, 1); | |
rr.reverse(arr, 2, 6); | |
rr.reverse(arr, 0, 6); | |
for(int i =0;i<arr.length;i++){ | |
System.out.println(arr[i]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RotateByOneArrayRotating { | |
public static void main(String[] args) { | |
int a[] ={1,2,3,4,5,6,7}; | |
int d=2; | |
RotateByOneArrayRotating r = new RotateByOneArrayRotating(); | |
r.rotateLeft(a, d, 7); | |
for(int i =0;i<a.length;i++){ | |
System.out.println(a[i]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RotationArrayDemo { | |
public static void main(String[] args) { | |
int[] a ={1,2,3,4,5,6}; | |
int d =2; | |
int temp[] =new int[d]; | |
NewerOlder