[Solved] How to print array index number?

Though your question is not very clear, it seems you just want o print the array index with contents, in that case you can follow the below code: for(int i=0;i<fruit.length;i++){ System.out.println((i+1)+”.”+fruit[i]); } Or if you want the number to store the index in the array contents, then you can go with: for(int i=0;i<fruit.length;i++) { System.out.print(“Fruit … Read more

[Solved] find the min and avg of student if it exist show the name of the student

Try to add a for loop to calcolate the sum of ages like this: for(i=0;i<age.length;i++){ sum+=age[i]; } And take out this below block out of for loop: avg= sum/age.length; System.out.println(“the avarage of all Students are :”+avg); System.out.println(“the minimum age of all Students : “+min); Like this: public static void main(String[] args) { // TODO code … Read more

[Solved] Android – Parse PHP json_encode to Java

You can simply parse the Json string as below – String json_string_from_server = “{\”test1\”:\”test1_value\”,\”test2\”:\”test2_value\”}”; JSONObject jObj = new JSONObject(json_string_from_server); String val_Test1 = jObj.getString(“test1”); String val_Test2 = jObj.getString(“test2”); case 2: String json_string_from_server = “{ “result” : [ {\”test1\”:\”test1_values_baru\”, \”test2\”:\”test2_values\”}, {\”test1\”:\”test‌​1_values\”, \”test2\”:\”test2_values\”} ] }”; JSONObject jObj = new JSONObject(json_string_from_server); JSONArray jResultArray = jObj.getJSONArray(“result”); for(int i=0; i<jResultArray.length(); i++){ … Read more

[Solved] Java scanner reading garbage

You are reading a RTF Document. If you want to read the text only you can try reading it into a byte array and parsing out the text using swings rtfeditorkit. Path path = Paths.get(“path/to/file”); byte[] data = Files.readAllBytes(path); RTFEditorKit rtfParser = new RTFEditorKit(); Document document = rtfParser.createDefaultDocument(); rtfParser.read(new ByteArrayInputStream(data), document, 0); String text = … Read more

[Solved] combine items of list

public class Main { public static void main(String[] args) { List<Integer> list = new LinkedList<>(); list.add(30); list.add(50); list.add(5); list.add(60); list.add(90); list.add(5); list.add(80); System.out.println(list); combine(list, 2, 3); System.out.println(list); } public static void combine(List<Integer> list, int indexA, int indexB) { Integer a = list.get(indexA); Integer b = list.get(indexB); list.remove(indexB); // [30, 50, 5, 90, 5, 80] list.add(indexA, … Read more

[Solved] Process unstructured and multiple line CSV in hadoop

Because you’re coping with multi-line data you cannot use a simple TextInputFormat to access your data. Thus you need to use a custom InputFormat for CSV files. Currently there is no built-in way of processing multi-line CSV files in Hadoop (see https://issues.apache.org/jira/browse/MAPREDUCE-2208), but luckily there’s come code on github you can try: https://github.com/mvallebr/CSVInputFormat. As far … Read more

[Solved] What is the point of abstract classes, when you could just do an interface [duplicate]

A few points to consider: Interfaces didn’t have default methods until Java 8. That a in your interface is implicitly final. Interfaces can’t define public mutable fields. Interfaces can’t define private (or protected, or package) fields. Interfaces can’t have protected or package methods; they couldn’t have private methods until Java 9. Abstract classes don’t have … Read more

[Solved] Parsing webpages to extract contents

Suggested readings Static pages: java.net.URLConnection and java.net.HttpURLConnection jsoup – HTML parser and content manipulation library Mind you, many of the pages will create content dynamically using JavaScript after loading. For such a case, the ‘static page’ approach won’t help, you will need to search for tools in the “Web automation” category.Selenium is such a toolset. … Read more