Skip to content

Instantly share code, notes, and snippets.

View oshi192's full-sized avatar

Yurii Kosakivskyi oshi192

  • Toronto ON, Canada
View GitHub Profile

insertion sort

int arr[]={5,2,8,3,9,12,12,22};
  for(int i=0;i<8;i++){
   cout<<arr[i]<<" ";   
  }
  cout<<endl;
  
  for(int j =1;j<8;j++){
 int key = arr[j];

Task 1:

The method takes a list of names. Returns a string of the form "1. Ivan, 3. Peter ...", only with names on odd indices, respectively.

    public static String constructString1(List<String> nameList) {
        return IntStream.range(0, nameList.size())
                .boxed()
                .map(x -> x * 2 + 1 + ". " + nameList.get(x))
                .collect(Collectors.joining(", "));
@oshi192
oshi192 / Quries.md
Last active November 27, 2018 09:37
Queries
  • 1 Написать запрос, считающий суммарное количество имеющихся на сайте новостей и обзоров. В результате выполнения запроса должно получиться: SUM 7
use test_tmp; 

select count(*) as sum 
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.function.Predicate;

public class MyArrayList<T> extends ArrayList<T> {
    @Override
    protected void removeRange(int fromIndex, int toIndex) {
        throw new UnsupportedOperationException("you cannot remove any objects in range");
@oshi192
oshi192 / Variant_1.md
Last active October 29, 2018 20:29
NumberOfDigits
        Integer[] array = {4, 5, -6, 4, 5, 3, 4, 2, 4, 5, 7,-1,-12,0,-8};
        List<Integer> numbers = new ArrayList<>(Arrays.asList(array));
        
        Map<Integer, Integer> numMap = new TreeMap<>();

        numbers.forEach(i->numMap.put(i, (numMap.get(i) != null) ? (numMap.get(i) + 1) : 1));
        numMap.entrySet()
                .stream()
 .forEach((x) -&gt; System.out.print(x.getKey() + "\t" + x.getValue() + "\n"));

How to kill a thread?

At this moment I found 3 solutions:

Thread.stop()

The thread is forcefully stopped after a given amount of time. The Thread.stop() method causes the thread to stop what it is doing and throw a ThreadDeath exception.

final class Runner implements Runnable {
    private String name;

Example #1

Main.java

import java.util.Arrays;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        List<Integer> ints = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 0);
        ints.forEach(i -> System.out.println(i + (i % 2 == 0 ? " even" : " odd")));
import java.awt.dnd.InvalidDnDOperationException;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.Scanner;

public class Main {
    private static final char ADD = '+';
    private static final char SUB = '-';