Process to divide the input character string with", "to make an array, count the number, multiply by 100, and output to the console
What?.java
package ha;
import java.util.Arrays;
public class Trash {
private static final String HA_IMIWAKANNAI = ",asd,asdadas,asda,sdas,asdasd,,asdasd,,,asd,";
public static void main(String[] args) {
trash(HA_IMIWAKANNAI);
}
private static void trash(String str) {
System.out.println(100 * Arrays.asList(str.split(",")).size());
}
}
I don't know what it means or what it's useful for
There is no piece of versatility
When will this be used
By the way
Separate the entered character string with", "
Array
Count the number
Multiply by 100
Process to output to console
Modification.java
package ha;
import java.util.Arrays;
import java.util.List;
public class Trash {
private static final String HA_IMIWAKANNAI = ",asd,asdadas,asda,sdas,asdasd,,asdasd,,,asd,";
public static void main(String[] args) {
trash(HA_IMIWAKANNAI);
}
private static void trash(String str) {
// System.out.println(100 * Arrays.asList(str.split(",")).size());
sysout(hundred(count(toArray(separate(str)))));
}
//Split
private static String[] separate(Object obj) {
return obj.toString().split(",");
}
//To list
private static List<String> toArray(String[] str) {
return Arrays.asList(str);
}
//count
private static int count(List<String> list) {
return list.size();
}
//Hundredfold
private static Integer hundred(int num) {
return num * 100;
}
//output
private static void sysout(Object obj) {
System.out.println(obj);
}
}
Divided too much
Well, the versatility is increasing, isn't it? I think it can be used in some areas as well!
I think there are many people who make their own StringUtil.
This is convenient Iteretor, T, Set, etc., which beginners don't know yet, are really useful, so please check them out.
Iterator makes for more versatile Collections such as List and Map that are careful about the order are Set Any good type is T Object is a class that can do anything
When you have to make multiple same processes by binding the type Let's think about how we can use them all at once.
However, if you use Optional poorly and allow nulls Be careful as it may cause an accident.
Versatility is amazing