[Solved] Need some advice on split() method in Java [closed]

Guessing that you want to split by the comma then this will make it String toSplit = “LXI H, 2000H, MOV M A”; // this is a regular expression, you should study regular expressions too String[] split = toSplit.replace(“,”, “”).split(” +”); for (String s : split) System.out.println(s); Read the String class in the java API … Read more

[Solved] method not being called java

Move your displayer(); below: @Override public void onClick(View v) { so you get: @Override public void onClick(View v) { displayer(); //Call method “displayer” when user presses button TextView Tv = (TextView) findViewById(R.id.TV); TextView Tv2 = (TextView) findViewById(R.id.Tv2); String date = sdf.format(calendar.getTime()); Tv.setText(“The current time is ” + date); String str = date.charAt(0) + “” + … Read more

[Solved] JAVA variable as 2 types [closed]

Java does not support union types; however, both of these types share the same base Object class, so you could assign either one of them to a variable defined like this Object something; something = “Hello World!”; something = new ArrayList(); // this is a collection. Odds are that you probably were thinking of a … Read more

[Solved] Eclipse:error missing (,} [closed]

The error messages are very descriptive. Check file MainActivity.java, line 65 and fix it. Similar for line 86. Anyway, these are the errors: Syntax error on token “)”, { expected MainActivity.java /CalculatorVamalV2/src/com/elitiv/calculatorvamalv2 line 65 Java Problem You missed a close brace } in the inner class definition: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); … Read more

[Solved] Sort a class array by a string attribute in Java

For Java 8 use a lambda expression and the Arrays sort function: Users[] someUsers = {user1, user2, user3}; Arrays.sort(someUsers, (a,b) -> a.firstName.compareTo(b.firstName)); For previous versions use a Collection Comparator: Users[] someUsers = {user1, user2, user3}; List<Users> userList = new ArrayList<Users>(Arrays.asList(someUsers)); Comparator<Users> comparator = new Comparator<Users>() { @Override public int compare(Users left, Users right) { return … Read more

[Solved] How to fetch database values between two dates [closed]

Here it is Method body public void callDatabase(String date1, String date2){ PreparedStatement stmt=con.prepareStatement(“select absentdt, period from stu_attendancemaster where classid=70 AND absentdt BETWEEN ‘”+date1+”‘ AND ‘”+date2+”‘ “); ResultSet rs=stmt.executeQuery(); while(rs.next()) { //get data here } } Method call String d1,d2; //initialize callDatabase(d1,d2); 3 solved How to fetch database values between two dates [closed]

[Solved] How to replace several characters on a single string to desired characters (java)?

public class TranslateChar { /** @param args */ public static void main(final String[] args) { final Map<Character, Character> mapCharCod = new HashMap<>(36); final Map<Character, Character> mapCharDecod = new HashMap<>(36); mapCharCod.put(‘A’, ‘Z’); mapCharCod.put(‘B’, ‘X’); mapCharCod.put(‘C’, ‘Y’); mapCharDecod.put(‘Z’, ‘A’); mapCharDecod.put(‘X’, ‘B’); mapCharDecod.put(‘Y’, ‘C’); final String toCod = “CAB”; StringBuilder sb = new StringBuilder(“{“); for (final char c … Read more