Create Scala Seq from Java, make Scala Seq a Java List

environment

Create Scala Seq from Java

Scala


Seq("a","b","c")

Java


  @SafeVarargs
  public static <T> Seq<T> Seq(T... values) {
    Seq<T> seq = JavaConverters.collectionAsScalaIterableConverter(Arrays.asList(values)).asScala().toSeq();
    return seq;
  }

sample

Equivalent to Scala's *** Seq (1,2,3) *** in Java

import java.util.Arrays;

import scala.collection.JavaConverters;
import scala.collection.Seq;

public class SeqInJava {

  public static void main(String[] args) {
    Seq<Integer> seqInJava = Seq(1, 2, 3);
  }

  @SafeVarargs
  public static <T> Seq<T> Seq(T... values) {
    Seq<T> seq = JavaConverters.collectionAsScalaIterableConverter(Arrays.asList(values)).asScala().toSeq();
    return seq;
  }
}

Make Scala Seq a Java List

JavaConverters.seqAsJavaList(Seq(1, 2, 3))

sample

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

import scala.collection.JavaConverters;
import scala.collection.Seq;

public class SeqToList {

  public static void main(String[] args) {

    List<Integer> list = JavaConverters.seqAsJavaList(Seq(1, 2, 3));
    System.out.println(list);

  }

  @SafeVarargs
  public static <T> Seq<T> Seq(T... values) {
    Seq<T> seq = JavaConverters.collectionAsScalaIterableConverter(Arrays.asList(values)).asScala().toSeq();
    return seq;
  }
}

Recommended Posts

Create Scala Seq from Java, make Scala Seq a Java List
[Java] Create a filter
[Note] Create a java environment from scratch with docker
Create a java method [Memo] [java11]
[Java] Create a temporary file
[Java] Make it a constant
Make a rhombus using Java
List data structure [Java / Scala]
How to make a Java container
Sort a List of Java objects
Run a batch file from Java
Access Teradata from a Java application
Create a Java project using Eclipse
Make a list map with LazyMap
Call TensorFlow Java API from Scala
[Java] Conversion from array to List
How to make a Java array
Create a named Skip List like redis sorted set in Java
Introduction to Scala from a Java perspective, decompiled and understood (basic)
Effective Java Item 25 Select a list from an array First half
[Java] Create and apply a slide master
How to make a Java calendar Summary
Make a family todo list with Sinatra
Introduction to Scala from a Java perspective (Class-Tuple edition) to decompile and understand
Create a MySQL environment with Docker from 0-> 1
Let's create a Java development environment (updating)
How to make a Discord bot (Java)
Make a family todo list with Sinatra
Try running a Kubernetes Job from Java
Create a TODO app in Java 7 Create Header
[Java] Let's make a DB access library!
[Java] Generate a narrowed list from multiple lists using the Stream API
Create a List that holds multiple classes
If a person from Java learns PHP
Let's make a calculator application with Java ~ Create a display area in the window
GetInstance () from a @Singleton class in Groovy from Java
[Java] From two Lists to one array list
Use native libraries from Scala via Java CPP + Java
Create a CSR with extended information in Java
[Windows] [IntelliJ] [Java] [Tomcat] Create a Tomcat9 environment with IntelliJ
Let's create a timed process with Java Timer! !!
Connect to Aurora (MySQL) from a Java application
To become a VB.net programmer from a Java shop
[Java] Create something like a product search API
I did Java to make (a == 1 && a == 2 && a == 3) always true
Try to create a bulletin board in Java
I tried hitting a Java method from ABCL
Programming beginners learn PHP from a Java perspective-variables-
[Java] Create a collection with only one element
I wanted to make (a == 1 && a == 2 && a == 3) true in Java
Let's create a super-simple web framework in Java
Get unixtime (seconds) from ZonedDateTime in Scala / Java
Use Matplotlib from Java or Scala with Matplotlib4j
[Java] Let's create a mod for Minecraft 1.16.1 [Introduction]
[Java] Get a random value from an array
[Java] Let's create a mod for Minecraft 1.14.4 [99. Mod output]
Ssh connect using SSHJ from a Java 6 app
Java memorandum (list)
Clone Java List.
About List [Java]
[Java] Let's create a mod for Minecraft 1.14.4 [0. Basic file]