Skip to content

Instantly share code, notes, and snippets.

View thospfuller's full-sized avatar
🎯
Focusing

Thomas P. Fuller thospfuller

🎯
Focusing
View GitHub Profile
@thospfuller
thospfuller / arrays-aslist-example.groovy
Created April 18, 2024 20:14
Example code for the article entitled "Tutorial: Learn how to use the java.util.Arrays asList method in Java now!"
import static java.util.Arrays.asList
import java.util.List
import java.util.Random
Random random = new Random()
int arrayCapacity = 10000
def numbers = new java.lang.Integer[arrayCapacity + 1]
@thospfuller
thospfuller / how-to-turn-an-array-into-an-arraylist-using-guava-example-three.groovy
Last active April 15, 2024 08:01
Turn an array into an ArrayList in Java using Guava
@Grapes(
@Grab(group='com.google.guava', module='guava', version='32.1.3-jre')
)
import static com.google.common.collect.Lists.newArrayList
def numbers = [1, 2, 3, 4, 5] as int[]
def result = newArrayList (numbers)
println "numbers.class: ${numbers.class.name}, result.class: ${result.class.name}, result: $result"
@thospfuller
thospfuller / how-to-convert-an-array-to-an-arraylist-in-java-using-constructor.groovy
Last active April 9, 2024 22:28
Example Zero: How to convert an array to an ArrayList in Java using the constructor.
@Grab(group='com.jamonapi', module='jamon', version='2.82')
import com.jamonapi.Monitor
import com.jamonapi.MonitorFactory
import static java.util.Arrays.asList
import java.util.stream.Collectors;
import java.util.List;
import java.util.Arrays;
import java.util.Random
@thospfuller
thospfuller / how-to-convert-an-array-to-an-arraylist-in-java-using-google-guava.groovy
Last active April 9, 2024 21:47
Example Three: How to turn an array into an ArrayList in Java using Google Guava.
@Grab(group='com.jamonapi', module='jamon', version='2.82')
import com.jamonapi.Monitor
import com.jamonapi.MonitorFactory
@Grab(group='com.google.guava', module='guava', version='32.1.3-jre')
import static com.google.common.collect.Lists.newArrayList
import java.util.stream.Collectors
import java.util.List
import java.util.Arrays
@thospfuller
thospfuller / how-to-convert-an-array-to-an-arraylist-in-java-using-java-util-stream.groovy
Created November 15, 2023 20:45
Example Two: How to turn an array into an ArrayList in Java using the java.util.stream API.
@Grab(group='com.jamonapi', module='jamon', version='2.82')
import com.jamonapi.Monitor
import com.jamonapi.MonitorFactory
import static java.util.Arrays.asList
import java.util.stream.Collectors;
import java.util.List;
import java.util.Arrays;
import java.util.Random
@thospfuller
thospfuller / how-to-convert-an-arraylist-to-an-int-array-in-java-no-unboxing-required-example.groovy
Created April 7, 2024 11:39
Java Autoboxing Performance: No Unboxing Required Performance Example
@Grab(group='com.jamonapi', module='jamon', version='2.82')
import com.jamonapi.Monitor
import com.jamonapi.MonitorFactory
import static java.util.Arrays.asList
import java.util.stream.Collectors
import java.util.List
import java.util.Arrays
import java.util.Random
@thospfuller
thospfuller / how-to-convert-an-arraylist-to-an-int-array-in-java-with-unboxing.groovy
Last active April 5, 2024 11:17
Java Autoboxing Performance: Unboxing Performance Example
@Grab(group='com.jamonapi', module='jamon', version='2.82')
import com.jamonapi.Monitor
import com.jamonapi.MonitorFactory
import static java.util.Arrays.asList
import java.util.stream.Collectors
import java.util.List
import java.util.Arrays
import java.util.Random
@thospfuller
thospfuller / how-to-convert-an-array-to-an-arraylist-in-java-using-addall-method.groovy
Last active March 15, 2024 20:15
Example One: How to turn an array into an ArrayList in Java using the addAll method (without the need to autobox).
@Grab(group='com.jamonapi', module='jamon', version='2.82')
import com.jamonapi.Monitor
import com.jamonapi.MonitorFactory
import static java.util.Arrays.asList
import java.util.stream.Collectors;
import java.util.List;
import java.util.Arrays;
import java.util.Random
@thospfuller
thospfuller / access-h2-database-browser-tutorial-example.groovy
Last active February 21, 2024 17:51
Example regarding how to configure the H2 Database web server programmatically.
package com.thospfuller
/**
* Tutorial regarding how to configure the H2 Database web server programmatically.
*
* Note that if we don't use the systemClassLoader we'll get the following exception:
*
* java.sql.SQLException: No suitable driver found for jdbc:h2:mem:example-db
*/
@GrabConfig(systemClassLoader=true)
@thospfuller
thospfuller / use-the-add-and-addall-methods-to-insert-elements-into-a-linkedlist.java
Created December 5, 2023 20:13
Use the add and addAll methods to insert elements into a Linked List
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
public class Main {
public static void main(String[] args) {
String[] values = {
"Apples",