如何"Thequickbrownfoxjumps"
在Java 中将字符串拆分为相同大小的子字符串.例如."Thequickbrownfoxjumps"
等于4的大小应该给出输出.
["Theq","uick","brow","nfox","jump","s"]
Run Code Online (Sandbox Code Playgroud)
类似问题:
我是Scala的新手,刚刚开始学习它.我想知道如何在Scala中初始化一个数组.
示例Java代码
String[] arr = { "Hello", "World" };
Run Code Online (Sandbox Code Playgroud)
Scala中上述代码的等价物是什么?
给出以下代码段:
int[] arr = {1, 2, 3};
for (int i : arr)
System.out.println(i);
Run Code Online (Sandbox Code Playgroud)
我有以下问题:
我刚刚创建了一个类型安全的Java n-tuple.
我正在使用一些非传统的方法来实现类型安全(我只是为了好玩).
有人可以就改进它或一些可能的缺陷提供一些意见.
public class Tuple {
private Object[] arr;
private int size;
private static boolean TypeLock = false;
private static Object[] lastTuple = {1,1,1}; //default tuple type
private Tuple(Object ... c) {
// TODO Auto-generated constructor stub
size=c.length;
arr=c;
if(TypeLock)
{
if(c.length == lastTuple.length)
for(int i = 0; i<c.length; i++)
{
if(c[i].getClass() == lastTuple[i].getClass())
continue;
else
throw new RuntimeException("Type Locked");
}
else
throw new RuntimeException("Type Locked");
}
lastTuple = this.arr;
}
public static void setTypeLock(boolean typeLock) {
TypeLock …
Run Code Online (Sandbox Code Playgroud) 假设我在Java中有一个地图,如下所示:
{
39:"39 to 41",
41:"41 to 43",
43:"43 to 45",
45:">=45"
}
Run Code Online (Sandbox Code Playgroud)
如果键是按排序顺序(使用treemap或linkedhashmap).现在,如果我尝试获得> = 39且<41的值.那么我应该得到字符串"39到41".如何有效地执行此操作?
如何转换"HelloWorld"
为"Hello World"
.分裂必须基于大写字母,但应排除第一个字母.
PS:我知道使用String.split然后合并.只是想知道是否有更好的方法.
我需要在整个工作空间中搜索包含"String1"或"String2"的所有文件.如何在eclipse搜索中实现这一点?
动物
public abstract class Animal {
String name;
public Animal(String name) {
this.name = name;
}
}
Run Code Online (Sandbox Code Playgroud)
狮子
public class Lion extends Animal {
public Lion(String name) {
super(name);
// TODO Auto-generated constructor stub
}
public void roar() {
System.out.println("Roar");
}
}
Run Code Online (Sandbox Code Playgroud)
鹿
public class Deer extends Animal {
public Deer(String name) {
super(name);
}
public void runAway() {
System.out.println("Running...");
}
}
Run Code Online (Sandbox Code Playgroud)
TestAnimals
public class TestAnimals {
public static void main(String[] args) {
Animal lion = new Lion("Geo");
Animal deer1 …
Run Code Online (Sandbox Code Playgroud)