Monthly Archives: March 2018

Kill Port by port number windows

http://therealdanvega.com/blog/2015/04/16/windows-kill-process-by-port-number Advertisements

Posted in Uncategorized | Leave a comment

Given 2 numbers as input multiply and print them

package test; import java.util.Scanner; /** * CommandLine Test * @author asharda * */ public class CommandLineTest extends TestJ9 { /** * @param args */ public static void main(String[] args) { int length=Integer.parseInt(args[0]); int a[]=new int[length]; Scanner s =new Scanner(System.in); for(int … Continue reading

Posted in Java, Uncategorized | Tagged | Leave a comment

Check if String is an anagram -Approach 1

/** * Validate if a String is an Anagram */ @Test public void testAnagram() { String s=”cinema”; String t=”maniee”; if(s.length()==t.length()) { char []sc=s.toCharArray(); char []tc=t.toCharArray(); List<Character> lst=new ArrayList<Character>(); List<Character> ldt=new ArrayList<Character>(); for(int i=0;i<sc.length;i++) { lst.add(sc[i]); ldt.add(tc[i]); } System.out.println(“Value of lst … Continue reading

Posted in Java, Uncategorized | Tagged , | Leave a comment

Using Optional Java

@Test public void testOptional() { Integer value1=10; Optional<Integer> a = Optional.ofNullable(value1); Optional<Integer> b = Optional.ofNullable(null); System.out.println(“Value of is a” + a + “Value of is b” + b); System.out.println(“Is A present “+ a.isPresent()); System.out.println(“Is B present “+ b.isPresent()); int c=b.orElse(0)+20; … Continue reading

Posted in Java, Java 8, Uncategorized | Tagged | Leave a comment

Strategy Design Pattern -Java

package test; /** * Basic Interface * @author asharda * */ interface StratgeyIn { void doOperation(int num1, int num2); }   /** * Implement OperationAdd * * @author asharda * */ class OpeartionAdd implements StratgeyIn { @Override public void doOperation(int … Continue reading

Posted in Data Structures, Design Pattern, Java, Uncategorized | Tagged | Leave a comment

Remove Duplicates,Sort and Reverse a List

@Test public void testReverseList() { List<Integer> aList = Arrays.asList(1, 2, 1, 8, 10, 20, 30, 40); List<Integer> bList = aList.stream().distinct().sorted().collect(Collectors.toList()); System.out.println(“Sorted List is ” + bList); List<Integer> cList = new ArrayList<Integer>(); for (int i = bList.size() – 1; i >= … Continue reading

Posted in Data Structures, Java, Java 8, Uncategorized | Tagged | Leave a comment

Remove duplicates and sort a List

@Test public void testStream() { List<Integer> aList = Arrays.asList(1, 2, 1, 8, 10, 20, 30, 40); System.out.println(“Sorted list seen is “); aList.stream().distinct().sorted().collect(Collectors.toList()).forEach(System.out::println); }

Posted in Java, Java 8, Uncategorized | Tagged | Leave a comment