alexa-tracking

Main Content

1024
1024
KASKUS
51
244
https://www.kaskus.co.id/thread/5308b2a9c3cb17ab528b4747/ask-java-buat-para-master-java-bisa-bantuin-dikit
[ask java] Buat para master java,, bisa bantuin dikit
Malem gan, ane barusan belajar java,, tapi masih pemula sekali.. ane punya masalah di simple coding ane...

Spoiler for Masalah 1 clear:



Spoiler for new Masalah 2:





Mohon bantuannya gan.. terimakasih
maap gan ya kalo salah tangkap pertannyaan agan, tapi mungkin gini gan..

cara konvensional
Code:

public class SampleApp {

private static List<String> getParts(String string, int partitionSize) {
List<String> parts = new ArrayList<String>();
int len = string.length();
for (int i = 0; i < len; i += partitionSize) {
parts.add(string.substring(i, Math.min(len, i + partitionSize)));
}
return parts;
}

public static void main(String[] args) {
final String binarySearch = "0100100101010100100101001010101010100100100100010101001010010";
List<String> result = new ArrayList<String>();
for (String part : getParts(binarySearch, 8)) {
result.add(part);
}
System.out.println(result);
}

}


cara regex :
Code:

public class SampleApp {

public static void main(String[] args) {
final String binarySearch = "0100100101010100100101001010101010100100100100010101001010010";
String[] arrGroup = binarySearch.split("(?<=\\G.{" + 8 + "})"); // 8, agan mo kelompokin jadi berapa.
System.out.println(Arrays.asList(arrGroup));
}

}
bukannya tinggal di split 8 char aja yah?
Quote:Original Posted By redhatgeek
maap gan ya kalo salah tangkap pertannyaan agan, tapi mungkin gini gan..

cara konvensional
Code:

public class SampleApp {

private static List<String> getParts(String string, int partitionSize) {
List<String> parts = new ArrayList<String>();
int len = string.length();
for (int i = 0; i < len; i += partitionSize) {
parts.add(string.substring(i, Math.min(len, i + partitionSize)));
}
return parts;
}

public static void main(String[] args) {
final String binarySearch = "0100100101010100100101001010101010100100100100010101001010010";
List<String> result = new ArrayList<String>();
for (String part : getParts(binarySearch, 8)) {
result.add(part);
}
System.out.println(result);
}

}


cara regex :
Code:

public class SampleApp {

public static void main(String[] args) {
final String binarySearch = "0100100101010100100101001010101010100100100100010101001010010";
String[] arrGroup = binarySearch.split("(?<=\\G.{" + 8 + "})"); // 8, agan mo kelompokin jadi berapa.
System.out.println(Arrays.asList(arrGroup));
}

}


Maksi bro bantuannya.. saya coba dulu
Mohon bantuannya agan agan sekalian emoticon-Toast emoticon-Toast