ArrayList Confusion and help!

basically id, like a few hints or tips on how to resolve this issue .. maybe a few things that I could read about arraylists and loop that would make it easier for me to understand! ..

the question arises:

Processing an array of characters: cList is an ArrayList of objects of type Character that has been declared and installed. Write a loop that will read characters that are not spaces, and print the number in the terminal window.

and second question:

Quoting through a string

Assuming the variable was declared as follows:

String s;

and that s is already assigned, write a loop statement that will print the s characters in reverse order (so if s = "HELLO", your loop should print "OLLEH").

for the first question I tried to do:

public ArrayList()
public static void main(String[] args) {
    int countBlank;
    char ch;
public ArrayList (int cList)      
{
    int cList = ;
    while(cList ){
        System.out.println(cList);
        }
        }

and second question:

, !

!

+3
4

ArrayList Javadoc mindprod.

cList arraylist . for. String, String.toCharArray() .

+2

, .

int counter = 0;
for (Character c : characters) {
    if (c == null {
        continue; // Note: You can have null values in an java.util.ArrayList
    }
    if (!Character.isSpaceChar(c)) {
        counter++;
    }
}
System.out.println(counter);  

:

for (int i = s.length() - 1; i >= 0; i--) {
    System.out.print(s.charAt(i));
}
+1

, , :

import java.text.CharacterIterator;
import java.text.StringCharacterIterator;

public class CI {
    private static final String text = "Hello";

    public static void main(String[] args) {
        CharacterIterator it = new StringCharacterIterator(text);

        for (char ch = it.last(); ch != CharacterIterator.DONE; ch = it
                .previous()) {
            System.out.print(ch);
        }
    }
}
0

1: import java.util. *;

ProcessListOfChars {

    public static int printCharsInListIgnoreSpaces(List<Character> cList){
            int count =0;
            for(Character character:cList){
            //      System.out.println("Value :"+character);
                    if(character!=null &&!character.toString().trim().equals("")){
                            ++count;
                    }
            }
            return count;
    }

    public static void main(String... args){
            List<Character> cList = new ArrayList<Character>();
            cList.add('c'); //Autoboxed char to Charater Wrapper Class
            cList.add(' '); //Space character
            cList.add('r');
            cList.add('b');
            cList.add(' ');
            int count = printCharsInListIgnoreSpaces(cList);
            System.out.println("Count of Characers :"+count);
    }

}

0

Source: https://habr.com/ru/post/1729822/


All Articles