在Scala中,如果我有以下配置:
id = 777
username = stephan
password = DG#%T@RH
Run Code Online (Sandbox Code Playgroud)
我们的想法是打开一个文件,将其转换为字符串,getLines然后根据左侧键获取右侧值.将常量配置值读入我的应用程序的最佳代码是什么?
客户用法: val username = config.get("username")
如何更新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) 在Java8,我该怎么形成Stream的String从扫描仪读取结果?
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 8下面的代码中,将整数转换3为位集并打印{0, 1},这意味着 的位表示3在位置上有 1 0,1即11。
System.out.println(BitSet.valueOf(new long[]{3}));
Run Code Online (Sandbox Code Playgroud)
我有兴趣将具有大值的BigIntegeror转换为相应的值,然后再返回 - 让对象(位表示)将其转换为( )。我还想知道对于各种整数值,哪种表示形式占用更多内存?long10000000BitSetBitSetBigIntegerlong
在我的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的情况下使用库?
我的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)