Skip to content

Instantly share code, notes, and snippets.

@peterszatmary
Last active October 30, 2016 15:19
Show Gist options
  • Save peterszatmary/1091362b06ea58017b37964108b96ee8 to your computer and use it in GitHub Desktop.
Save peterszatmary/1091362b06ea58017b37964108b96ee8 to your computer and use it in GitHub Desktop.
public class JavaQuestions {
public willCompileOrNot() {
https://www.github.com/peterszatmary/
System.out.println("will compile or not ?");
}
public void question1() {
System.out.println(null);
}
public void question2() {
Integer in = null;
Integer v = in.valueOf(100);
System.out.println("v = " + v);
}
public void recursiveWalker(File file) {
System.out.println(file.getAbsolutePath());
File[] children = file.listFiles();
if (null != children) {
for (File child : children) {
recursiveWalker(child);
}
}
}
public static nonRecursiveWalker(String path, int d) {
File root = new File(path);
List<File> ex = new LinkedList<>();
ex.add(root);
for (int depth = 0; depth < d; depth++) {
File[] fs = ex.toArray(new File[ex.size()]);
ex.clear();
for (File file: fs) {
System.out.println("depth = " + depth + ", file = " + file);
if (file.isDirectory()) {
ex.addAll(Arrays.asList(file.listFiles()));
}
}
}
}
public boolean isAcyclic(String s1, String s2) {
return (s1 != null && s2 != null) && (s1.length() == s2.length()) && ((s1 + s1).indexOf(s2) != -1);
}
public void howLong() {
long start = System.nanoTime();
// computation
long end = System.nanoTime();
System.out.println("time: " + (end - start) + " ns");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment