About 50 results
Open links in new tab
  1. What is the easiest/best/most correct way to iterate through the ...

    Jan 6, 2017 · 497 Some ways to iterate through the characters of a string in Java are: Using StringTokenizer? Converting the String to a char[] and iterating over that. What is the …

  2. java - How to iterate through a String - Stack Overflow

    How can I iterate through a string in Java? I'm trying to use a foreach style for loop for (char x : examplestring) { //action }

  3. java - Fastest way to iterate over all the chars in a String - Stack ...

    Jan 17, 2012 · Field access is back as the clear winner. Note than the program will need to use byte [] access for Java 9+ version jvms. It all depends on the length of the String being inspected. If, as the …

  4. How do I efficiently iterate over each entry in a Java Map?

    If I have an object implementing the Map interface in Java and I wish to iterate over every pair contained within it, what is the most efficient way of going through the map? Will the ordering of

  5. Iterate through string array in Java - Stack Overflow

    Jul 15, 2011 · I have String array with some components, this array has 5 components and it vary some times. What I would like to do is to iterate through that array and get the first component and the …

  6. loops - Ways to iterate over a list in Java - Stack Overflow

    Essentially, there are only two ways to iterate over a list: by using an index or by using an iterator. The enhanced for loop is just a syntactic shortcut introduced in Java 5 to avoid the tedium of explicitly …

  7. What is the best way to iterate over the lines of a Java String ...

    Feb 13, 2012 · Before Java 11, BufferedReader+StringReader the fastest method to read a String line by line. But with Java 11+, it's faster to use String.lines().

  8. java - Iterate through a HashMap - Stack Overflow

    Jul 1, 2009 · Extracted from the reference How to Iterate Over a Map in Java: There are several ways of iterating over a Map in Java. Let's go over the most common methods and review their advantages …

  9. How can I iterate over a string in Java? - Stack Overflow

    May 30, 2011 · 0 Every String is also a CharSequence in Java. Therefore, you can easily iterate over a String using a simple for loop:

  10. How do I apply the for-each loop to every character in a String?

    Mar 16, 2010 · So I want to iterate for each character in a string. So I thought: for (char c : "xyz") but I get a compiler error: MyClass.java:20: foreach not applicable to expression type How can I do this?