java.lang
Code IndexAdd Codota to your IDE (free)

Best Java code snippets using java.lang (Showing top 20 results out of 624,672)

origin: stackoverflow.com

 "abc" == new String("abc")    // true
"abc" === new String("abc")   // false
origin: stackoverflow.com

 Math.random()
          |
[0 .................................... 1)
[0 .................................... max - min)
          |
          x (what we need)
origin: stackoverflow.com

 private boolean isMyServiceRunning(Class<?> serviceClass) {
  ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
  for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
    if (serviceClass.getName().equals(service.service.getClassName())) {
      return true;
    }
  }
  return false;
}
origin: stackoverflow.com

 public static String humanReadableByteCount(long bytes, boolean si) {
  int unit = si ? 1000 : 1024;
  if (bytes < unit) return bytes + " B";
  int exp = (int) (Math.log(bytes) / Math.log(unit));
  String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp-1) + (si ? "" : "i");
  return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
}
origin: ReactiveX/RxJava

  static void sleep(int millis) {
    try {
      Thread.sleep(millis);
    } catch (InterruptedException ex) {
      throw new RuntimeException(ex);
    }
  }
}
origin: stackoverflow.com

 if (string.contains("-")) {
  // Split it.
} else {
  throw new IllegalArgumentException("String " + string + " does not contain -");
}
origin: stackoverflow.com

 String string = "004-034556";
String[] parts = string.split("(?<=-)");
String part1 = parts[0]; // 004-
String part2 = parts[1]; // 034556
origin: ReactiveX/RxJava

  public void waitToFinish() {
    try {
      t.join();
    } catch (InterruptedException e) {
      throw new RuntimeException(e);
    }
  }
}
origin: ReactiveX/RxJava

  @Override
  public boolean test(Throwable t) throws Exception {
    return t.getMessage() != null && t.getMessage().contains("Forced");
  }
});
origin: ReactiveX/RxJava

@Override
public Integer apply(Integer t1) {
  if (c++ <= 1) {
    // slow
    try {
      Thread.sleep(500);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
  return t1;
}
origin: ReactiveX/RxJava

ParamOverride(Class<?> clazz, int index, ParamMode mode, String name, Class<?>... arguments) {
  this.clazz = clazz;
  this.index = index;
  this.mode = mode;
  this.name = name;
  this.arguments = arguments;
  try {
    clazz.getMethod(name, arguments);
  } catch (Exception ex) {
    throw new AssertionError(ex);
  }
}
origin: ReactiveX/RxJava

public CrashDummy assertError(Class<? extends Throwable> clazz) {
  if (!clazz.isInstance(error)) {
    throw new AssertionError("Different error: " + error);
  }
  return this;
}
origin: stackoverflow.com

 function delay() {
 // `delay` returns a promise
 return new Promise(function(resolve, reject) {
  // Only `delay` is able to resolve or reject the promise
  setTimeout(function() {
   resolve(42); // After 3 seconds, resolve the promise with value 42
  }, 3000);
 });
}

delay().then(function(v) { // `delay` returns a promise
 console.log(v); // Log the value once it is resolved
}).catch(function(v) {
 // Or do something else if it is rejected 
 // (it would not happen in this example, since `reject` is not called).
});
origin: stackoverflow.com

 function guid() {
 return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
  s4() + '-' + s4() + s4() + s4();
}

function s4() {
 return Math.floor((1 + Math.random()) * 0x10000)
  .toString(16)
  .substring(1);
}

document.getElementById('jsGenId').addEventListener('click', function() {
 document.getElementById('jsIdResult').value = guid();
})
origin: stackoverflow.com

 // or it's a property that can throw an error
Object.defineProperty(window, "myVariable", { 
  get: function() { throw new Error("W00t?"); }, 
  set: undefined 
});
if (myVariable) {
  // Error: W00t?
}
origin: stackoverflow.com

 String string = "004-034556-42";
String[] parts = string.split("-", 2);
String part1 = parts[0]; // 004
String part2 = parts[1]; // 034556-42
origin: ReactiveX/RxJava

public void waitToFinish() {
  try {
    t.join();
  } catch (InterruptedException e) {
    throw new RuntimeException(e);
  }
}
origin: stackoverflow.com

 // These two have the same value
new String("test").equals("test") // --> true 

// ... but they are not the same object
new String("test") == "test" // --> false 

// ... neither are these
new String("test") == new String("test") // --> false 

// ... but these are because literals are interned by 
// the compiler and thus refer to the same object
"test" == "test" // --> true 

// ... but you should really just call Objects.equals()
Objects.equals("test", new String("test")) // --> true
Objects.equals(null, "test") // --> false
origin: stackoverflow.com

 String string = "004-034556";
String[] parts = string.split("-");
String part1 = parts[0]; // 004
String part2 = parts[1]; // 034556
origin: stackoverflow.com

 String string = "004-034556";
String[] parts = string.split("(?=-)");
String part1 = parts[0]; // 004
String part2 = parts[1]; // -034556
java.lang

Most used classes

  • String
  • Object
  • Class
    Instances of the class Class represent classes and interfaces in a running Java application. An enum
  • System
    Provides access to system-related information and resources including standard input and output. Ena
  • IllegalArgumentException
  • StringBuilder,
  • RuntimeException,
  • Exception,
  • IllegalStateException,
  • Thread,
  • Math,
  • Long,
  • Boolean,
  • UnsupportedOperationException,
  • Throwable,
  • Method,
  • StringBuffer,
  • Deprecated,
  • Double

For IntelliJ IDEA,
Android Studio or Eclipse

  • Search for JavaScript code betaCodota IntelliJ IDEA pluginCodota Android Studio pluginCode IndexSign in
  • EnterpriseFAQAboutBlogContact Us
  • Plugin user guideTerms of usePrivacy policyCodeboxFind Usages
Add Codota to your IDE (free)