congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
java.util
Code IndexAdd Tabnine to your IDE (free)

How to use java.util

Best Java code snippets using java.util (Showing top 20 results out of 517,329)

origin: stackoverflow.com

 for (Map.Entry<String, Object> entry : map.entrySet()) {
  String key = entry.getKey();
  Object value = entry.getValue();
  // ...
}
origin: stackoverflow.com

 Map<String, Object> map = ...;

for (String key : map.keySet()) {
  // ...
}
origin: stackoverflow.com

 public static void printMap(Map mp) {
  Iterator it = mp.entrySet().iterator();
  while (it.hasNext()) {
    Map.Entry pair = (Map.Entry)it.next();
    System.out.println(pair.getKey() + " = " + pair.getValue());
    it.remove(); // avoids a ConcurrentModificationException
  }
}
origin: ReactiveX/RxJava

static void addDefaultInstance(Class<?> clazz, Object o, String tag) {
  List<Object> list = defaultInstances.get(clazz);
  if (list == null) {
    list = new ArrayList<Object>();
    defaultInstances.put(clazz, list);
  }
  list.add(o);
  list.add(tag);
}
origin: iluwatar/java-design-patterns

 /**
  * Collects the remaining objects of the given iterator into a List.
  * 
  * @return a new List with the remaining objects.
  */
 public static <E> List<E> toList(Iterator<E> iterator) {
  List<E> copy = new ArrayList<>();
  while (iterator.hasNext()) {
   copy.add(iterator.next());
  }
  return copy;
 }
}
origin: stackoverflow.com

 List<String> list = new ArrayList<>();

// This is a clever way to create the iterator and call iterator.hasNext() like
// you would do in a while-loop. It would be the same as doing:
//     Iterator<String> iterator = list.iterator();
//     while (iterator.hasNext()) {
for (Iterator<String> iterator = list.iterator(); iterator.hasNext();) {
  String string = iterator.next();
  if (string.isEmpty()) {
    // Remove the current element from the iterator and the list.
    iterator.remove();
  }
}
origin: stackoverflow.com

 List<String> list = new ArrayList<String>();
//add some stuff
list.add("android");
list.add("apple");
String[] stringArray = list.toArray(new String[0]);
origin: ReactiveX/RxJava

private static Map<String, String> getMap(String prefix) {
  Map<String, String> m = new HashMap<String, String>();
  m.put("firstName", prefix + "First");
  m.put("lastName", prefix + "Last");
  return m;
}
origin: ReactiveX/RxJava

  @Override
  public Collection<String> apply(Integer t1) {
    if (t1 == 2) {
      return new ArrayList<String>();
    } else {
      return new HashSet<String>();
    }
  }
};
origin: ReactiveX/RxJava

TestObservable(CountDownLatch once, CountDownLatch okToContinue, T... values) {
  this.values = Arrays.asList(values);
  this.size = this.values.size();
  this.once = once;
  this.okToContinue = okToContinue;
  this.seed = null;
}
origin: stackoverflow.com

 @Test(expected=IndexOutOfBoundsException.class)
public void testIndexOutOfBoundsException() {
  ArrayList emptyList = new ArrayList();
  Object o = emptyList.get(0);
}
origin: ReactiveX/RxJava

  @Override
  public Iterable<Integer> apply(Integer v) throws Exception {
    if ((v & 1) == 1) {
      return Collections.emptyList();
    }
    return Arrays.asList(1, 2);
  }
})
origin: stackoverflow.com

 Map<String, String> map = ...
for (Map.Entry<String, String> entry : map.entrySet())
{
  System.out.println(entry.getKey() + "/" + entry.getValue());
}
origin: iluwatar/java-design-patterns

/**
 * An eagerly evaluated stream of customers stored in memory.
 */
@Override
public Stream<Customer> getAll() {
 return idToCustomer.values().stream();
}
origin: stackoverflow.com

 if (!Date.now) {
  Date.now = function() { return new Date().getTime(); }
}
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

 static String convertStreamToString(java.io.InputStream is) {
  java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
  return s.hasNext() ? s.next() : "";
}
origin: stackoverflow.com

 import java.util.TimeZone;

public class Test {
  public static void main(String[] args) throws Exception {
    long startOf1900Utc = -2208988800000L;
    for (String id : TimeZone.getAvailableIDs()) {
      TimeZone zone = TimeZone.getTimeZone(id);
      if (zone.getRawOffset() != zone.getOffset(startOf1900Utc - 1)) {
        System.out.println(id);
      }
    }
  }
}
origin: ReactiveX/RxJava

private static Map<String, String> getMap(String prefix) {
  Map<String, String> m = new HashMap<String, String>();
  m.put("firstName", prefix + "First");
  m.put("lastName", prefix + "Last");
  return m;
}
origin: stackoverflow.com

 var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();

if(dd<10) {
  dd='0'+dd
} 

if(mm<10) {
  mm='0'+mm
} 

today = mm+'/'+dd+'/'+yyyy;
document.write(today);
java.util

Most used classes

  • List
  • Map
  • ArrayList
    Resizable-array implementation of the List interface. Implements all optional list operations, and p
  • HashMap
    HashMap is an implementation of Map. All optional operations are supported.All elements are permitte
  • Set
    A collection that contains no duplicate elements. More formally, sets contain no pair of elements e1
  • Collections,
  • Map$Entry,
  • Iterator,
  • HashSet,
  • Collection,
  • Date,
  • Pattern,
  • Properties,
  • Matcher,
  • Stream,
  • LinkedList,
  • Optional,
  • Collectors,
  • Objects
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now