小编Ste*_*sky的帖子

从Scala中的config读取值

在Scala中,如果我有以下配置:

id = 777
username = stephan
password = DG#%T@RH
Run Code Online (Sandbox Code Playgroud)

我们的想法是打开一个文件,将其转换为字符串,getLines然后根据左侧键获取右侧值.将常量配置值读入我的应用程序的最佳代码是什么?

客户用法: val username = config.get("username")

scala file

11
推荐指数
1
解决办法
2万
查看次数

如何根据条件更新Atomic?

如何更新AtomicInteger当前值是否小于给定值?这个想法是:

AtomicInteger ai = new AtomicInteger(0);
...
ai.update(threadInt); // this call happens concurrently
...
// inside AtomicInteger atomic operation
synchronized {
    if (ai.currentvalue < threadInt)
        ai.currentvalue = threadInt;
}
Run Code Online (Sandbox Code Playgroud)

java concurrentmodification atomicinteger

11
推荐指数
2
解决办法
2862
查看次数

如何在Java中将扫描仪字符串转换为Stream?

Java8,我该怎么形成StreamString从扫描仪读取结果?

InputStream is = A.class.getResourceAsStream("data.txt");
Scanner scanner = new Scanner(new BufferedInputStream(is), "UTF-8");
while (scanner.hasNextLine()) {
    System.out.println(scanner.nextLine());
}
Run Code Online (Sandbox Code Playgroud)

这就是将扫描仪变成我想要迭代使用的流forEach.

java java-8 java-stream

6
推荐指数
1
解决办法
7182
查看次数

Java 从 BigInteger 到 BitSet 并返回

Java 8下面的代码中,将整数转换3为位集并打印{0, 1},这意味着 的位表示3在位置上有 1 0111

System.out.println(BitSet.valueOf(new long[]{3}));
Run Code Online (Sandbox Code Playgroud)

我有兴趣将具有大值的BigIntegeror转换为相应的值,然后再返回 - 让对象(位表示)将其转换为( )。我还想知道对于各种整数值,哪种表示形式占用更多内存?long10000000BitSetBitSetBigIntegerlong

java bitset bigint

5
推荐指数
1
解决办法
4464
查看次数

是否可以在不安装Play的情况下使用JSON库?

在我的build.sbt:

lazy val commonSettings = Seq(
  version := "1.0.0",
  scalaVersion := "2.11.6"
)
lazy val root = (project in file(".")).
  settings(commonSettings: _*).
  settings(
    name := "myapp",
    libraryDependencies ++= Seq(
      "com.typesafe.play" % "play-json_2.11" % "2.3.4",
      "org.scalatest" % "scalatest_2.11" % "2.2.4" % "test",
      "junit" % "junit" % "4.12" % "test"
    )
  )
resolvers ++= Seq("Typesafe Repo" at "http://repo.typesafe.com/typesafe/releases/")
Run Code Online (Sandbox Code Playgroud)

它汇编得很好.现在我使用的代码,import play.api.libs.json._但编译器给出错误说"找不到:对象播放".显然我没有安装游戏.是否可以在play-json不安装Play的情况下使用库?

json scala playframework-2.0

4
推荐指数
1
解决办法
1035
查看次数

如何声明播放json依赖?

我的build.sbt文件(sbt版本0.13.8):

lazy val commonSettings = Seq(
  version := "1.0.0",
  scalaVersion := "2.11.6"
)

resolvers += "Typesafe Repo" at "http://repo.typesafe.com/typesafe/releases/"

lazy val root = (project in file(".")).
  settings(commonSettings: _*).
  settings(
    name := "myapp",
    libraryDependencies ++= Seq(
      "com.typesafe.play" % "play-json" % "2.3.4",
      "org.scalatest" % "scalatest_2.11" % "2.2.4" % "test",
      "junit" % "junit" % "4.12" % "test"
    )
  )

scalacOptions ++= Seq("-unchecked", "-feature", "-deprecation")
Run Code Online (Sandbox Code Playgroud)

我在尝试编译项目时遇到此错误:

[trace] Stack trace suppressed: run last *:update for the full output.
[error] (*:update) sbt.ResolveException: …
Run Code Online (Sandbox Code Playgroud)

scala sbt play-json

1
推荐指数
1
解决办法
2127
查看次数