Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Learning | Creating

Vishal Parashar visparashar

🎯
Learning | Creating
View GitHub Profile
View RateLimiterDemo.java
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"));
View ReentranceLockDemo.java
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 {
View temp.java
// 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)
View CountDownLatch.java
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];
View WithoutLambdaExp.java
@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(){
View CE.Java
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).
View MF.java
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};
View RotateByReversal.java
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]);
View RotateByOneArrayRotating.java
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]);
}
View RotationArrayDemo.java
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];