Skip to content

Instantly share code, notes, and snippets.

View pablohdzvizcarra's full-sized avatar
🛏️
Need Sleep

Pablo Hernandez pablohdzvizcarra

🛏️
Need Sleep
View GitHub Profile
@pablohdzvizcarra
pablohdzvizcarra / BinarySortStrange.java
Created February 6, 2025 13:09
Strange binary sort algorithm implementation, very weird
class Solution {
public int search(int[] nums, int target) {
int left = 0;
int right = nums.length - 1;
int result = -1;
int n = nums.length;
while (n >= 1) {
int middle = (left + right) / 2;
if (target == nums[middle]) {
@pablohdzvizcarra
pablohdzvizcarra / data.txt
Last active March 8, 2025 19:31
How to read the content of a file with Java text file
1.The angel from my nightmare
2.The shadow in the background of the morgue
3.The unsuspecting victim of darkness in the valley
4.We can live like Jack and Sally, if we want
5.Where you can always find me
6.And we'll have Halloween on Christmas
7.And, in the night, we'll wish this never ends
8.We'll wish this never ends.
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
public class Example1 {
public static void main(String[] args) {
String filePath = "data.txt";
try {
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class Example2 {
public static void main(String[] args) {
String filePath = "data.txt";
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
String line;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class Example3 {
public static void main(String[] args) {
String filePath = "data.txt";
try {
byte[] contentBytes = Files.readAllBytes(Paths.get(filePath));
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
public class Example4 {
public static void main(String[] args) {
String filePath = "data.txt";
int bufferSize = 100; // number of bytes
@pablohdzvizcarra
pablohdzvizcarra / Test.java
Created March 22, 2025 14:06
How to test if a test does not throws an exception in Java
package com.github.pablohdzvizcarra.lesson28;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class MethodValidatorTest {
@Test