Skip to main content

All Questions

-1 votes
1 answer
111 views

How to efficiently search an element in a TreeSet without using contains?

I'm quite new to Java and its libraries so its possible this question comes as a dumb or obvious one. Assuming I have a class like this: public class Person implements Comparable<Person> { ...
Pirata's user avatar
  • 1
2 votes
0 answers
440 views

Java ConcurrentHashMap iterating via entrySet vs keySet

Many articles compare these approaches and all are in favor of entrySet over keySet. All of them take into account the speed, but none heap usage. https://coderanch.com/t/203203/java/entrySet-keySet-...
Jovan Perovic's user avatar
0 votes
1 answer
152 views

How to iterate through a fixed tridimensional matrix efficiently (java)

As part of a program I'm building I need to iterate through all the points in a tridimensional matrix. On each point I need to execute a method that takes int x, int y, int z as parameters. The ...
HappilyCoding's user avatar
1 vote
2 answers
685 views

Is using Pattern/Matcher more efficient than looping through a string and looking for characters?

I am working on a project that will look through a java file for a particular method, and output the lines that method occupies to a file. I am already using a Pattern and Matcher to find the method, ...
Chandler Davis's user avatar
-2 votes
5 answers
1k views

List are given in map<key,values> as values,how can I find one or more key which have largest list size java

I have written a method which returns a map. The structure of the map is: Map<String, List<String>> map; The map can contain more than 1000 keys, and each key can contain a list more than ...
Shaw's user avatar
  • 13
1 vote
5 answers
3k views

Whats the performance cost on iterating on a list multiple times

I have a List I need to iterate through and perform work on along the way. My problem is that, for my program, its difficult to do all the work needed on the list every loop due to concurrency. My ...
Sammy Guergachi's user avatar
1 vote
1 answer
56 views

Iteration run faster for "even teams" code

I am coding to create two "even teams" based on the players' scores (puntajes). The algorithm runs through the array of players and compares the score of each one to get a minimum difference and ...
Juan Btesh's user avatar
1 vote
4 answers
378 views

Optimal way to check for common element among many lists?

I understand that ArrayList<>'s are fastest for searching (O(1) vs. O(n)) and LinkedList<>'s are fastest for inserting & deleting (O(1) vs. O(n)). My question is, if using a ...
dunck's user avatar
  • 398
0 votes
1 answer
211 views

Performance: Fastest way to check if a List<String> contains a specific String

In the program I'm writing on, I'll have to check if a List (actually I can replace the type of Collection if necessary) contains a specific String. Is this the fastest way to do it? private boolean ...
Jdv's user avatar
  • 993
7 votes
1 answer
15k views

Collection iteration with forEach() in multiple threads or with forEach() and lambdas

Let say I have an array with a thousands independent objects inside. Now I want to pass over each of them and perform the same operation, for instance, change the value of a specific field. At first ...
Mike's user avatar
  • 14.7k
1 vote
1 answer
446 views

Iterator raw type should be used or not? [duplicate]

I was wondering about the difference between this statement : Iterator<String> it = map.values().iterator(); And this statement : Iterator it = map.values().iterator(); And Also Why is it a ...
Rbih Zaki's user avatar
1 vote
5 answers
112 views

How can I make this more efficient?

My program gives a String answer based on comparisons of Integer input. Would there be a more efficient way of doing this instead of prompting the user 3 separate times and calling numberVerify three ...
Evan's user avatar
  • 374
1 vote
1 answer
91 views

Java efficient iterating over char

As a part of my implementation I need to implement iterating over chars as efficient as possible. Here is a part of my source code that I wrote: public int normalize(char s[], int len) { for (int ...
Ali's user avatar
  • 1,879
2 votes
4 answers
216 views

Substitute statements in code with loops in Java

I have these two pieces of code: int prevY = 0; // this is the function InsertionSort applied to i StdDraw.setPenColor(Color.blue); for (int i = 1; i <= N; i++) { int x = i;...
Eduardo Portet's user avatar
1 vote
0 answers
89 views

Why does this recursive image comparison take less then primitive iterative one? (JAVA 8)

I have run into a little situation that puzzles me. Would someone be able to explain it? I have written an algorithm in Java that compares two images by first comparing the two middle columns of the ...
TeabagD's user avatar
  • 689

15 30 50 per page