Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

when using a array of strings in java, convert it to lowercase

I got a one dimensional array of strings in java, in which i want to change all strings to lowercase, to afterwards compare it to the original array so i can have the program check whether there are no uppercase chars in my strings/array.

i've tried using x.toLowercase but that only works on single strings. Is there a way for me to convert the whole string to lowercase?

Kind regards, Brand

like image 352
Rdhao Avatar asked Dec 07 '11 13:12

Rdhao


4 Answers

arraylist.stream().map(s -> s.toLowerCase()).collect(Collectors.toList()) 

may help you

like image 167
Федор Дао Avatar answered Nov 20 '22 12:11

Федор Дао


If you want a short example, you could do the following

String[] array = ...
String asString = Arrays.toString(array);
if(asString.equals(asString.toLowerCase())
   // no upper case characters.
like image 38
Peter Lawrey Avatar answered Nov 20 '22 11:11

Peter Lawrey


String  array[]= {"some values"};

String str= String.join(',',array);

String array_uppercase[]=str.toLowerCase().split(',');
like image 4
SuRa Avatar answered Nov 20 '22 12:11

SuRa


Just two line

     String[] array = {"One", "Two"};
    for(int i=0;i<array.length;i++){
        if(!array[i].equals(array[i].toLowerCase()))
            System.out.println("It contains uppercase char");
        array[i] = array[i].toLowerCase();
    }
    for(int i=0;i<array.length;i++)
        System.out.println(array[i]);

OUTPUT:

It contains uppercase char
It contains uppercase char
one
two
like image 3
dku.rajkumar Avatar answered Nov 20 '22 13:11

dku.rajkumar