java Things that are searched many times [java beginner]

Will be added at any time.

1, how to take length

int array
int [] intArray = {1,2,3,4,5};
System.out.println(intArray.length);
Output: 5
String string
String text = "text";
System.out.println(text.length());
Output: 4
StringBuilder type string
StringBuilder sb = new StringBuilder();
sb.append("text");
System.out.println(sb.length());
Output: 4

2, type conversion

String >> int conversion
String StringA = "0";
int intA = Integer.parseInt(StringA);
int >> String conversion
int intB = 0;
String stringB = String.valueOf(intB);
int >> Integer conversion
int intC = 0;
Integer integerC = intC;        
Integer >> int conversion
Integer integerD = 0;
int intD = integerD.intValue();
char >> String conversion
String strText = String.valueOf('a');

3, Array sort (when each element is Integer)

Array sort (ascending order)
Arrays.sort(array);
Array sort (descending order)
Arrays.sort(array, Collections.reverseOrder());

Or

Arrays.sort(array, Collections.reverseOrder());
String sort
String strtext = "cbda";
System.out.println(strtext);
char[] charText = strtext.toCharArray();
Arrays.sort(charText);
String sortedText = new String(charText);
System.out.println(sortedText);
output
cbda
abcd

Initialization

List initialization
List<Integer> list1 = Arrays.asList(1,2);

Recommended Posts

java Things that are searched many times [java beginner]
java beginner 4
java beginner 3
Java Beginner Exercises
Java Exercise "Beginner"
Features that are likely to enter Java 10 for now