N
Naveen Reddy
Hello all,
I'm a Java & OOPS newbie (the question below will make that clear
I'm trying to return more than one value from a class.
Could anyone please give some pointers on this?
I need to assign two variables, classPathSeparator and
filePathSeparator based on the platform the program is being run on
(Solaris or WIN). The initial program works fine.
============================================================================
public class multipleReturn {
public static void main ( String args[] ) {
String filePathSeparator = getFilePathSeparator() ;
System.out.println("File Path Separator is: " +
filePathSeparator) ;
String classPathSeparator = getClassPathSeparator() ;
System.out.println("Class Path Separator is: " +
classPathSeparator) ;
}
public static String getFilePathSeparator() {
// For a variety of reasons, I really cant use the
// Sysem Property , "file.separator".
String os = System.getProperty("os.name") ;
String fileSeparator = null ;
if ( os.equals("SunOS") ) {
fileSeparator = "/" ;
} else {
fileSeparator = "\\" ;
}
return fileSeparator ;
}
public static String getClassPathSeparator() {
String os = System.getProperty("os.name") ;
String classSeparator = null ;
if ( os.equals("SunOS") ) {
classSeparator = ":" ;
} else {
classSeparator = ";" ;
}
return classSeparator ;
}
}
============================================================================
I'm trying to get it working in a more elegant way.
I realize that the code in the two classes is pretty much the same and
want to write a single class, which returns classpath and filepath
separators.
But, I dont see a way to return two strings.
a) Do I have to return an array? And then index out of this array to
get the classpath or filepath separators.
b) Can I write an object which holds these values and return that
object?
How do I then 'retrieve' any one single separator from the returned
values?
Could anyone please point me in the right direction.
Thanks for your time,
Reddy
I'm a Java & OOPS newbie (the question below will make that clear
I'm trying to return more than one value from a class.
Could anyone please give some pointers on this?
I need to assign two variables, classPathSeparator and
filePathSeparator based on the platform the program is being run on
(Solaris or WIN). The initial program works fine.
============================================================================
public class multipleReturn {
public static void main ( String args[] ) {
String filePathSeparator = getFilePathSeparator() ;
System.out.println("File Path Separator is: " +
filePathSeparator) ;
String classPathSeparator = getClassPathSeparator() ;
System.out.println("Class Path Separator is: " +
classPathSeparator) ;
}
public static String getFilePathSeparator() {
// For a variety of reasons, I really cant use the
// Sysem Property , "file.separator".
String os = System.getProperty("os.name") ;
String fileSeparator = null ;
if ( os.equals("SunOS") ) {
fileSeparator = "/" ;
} else {
fileSeparator = "\\" ;
}
return fileSeparator ;
}
public static String getClassPathSeparator() {
String os = System.getProperty("os.name") ;
String classSeparator = null ;
if ( os.equals("SunOS") ) {
classSeparator = ":" ;
} else {
classSeparator = ";" ;
}
return classSeparator ;
}
}
============================================================================
I'm trying to get it working in a more elegant way.
I realize that the code in the two classes is pretty much the same and
want to write a single class, which returns classpath and filepath
separators.
But, I dont see a way to return two strings.
a) Do I have to return an array? And then index out of this array to
get the classpath or filepath separators.
b) Can I write an object which holds these values and return that
object?
How do I then 'retrieve' any one single separator from the returned
values?
Could anyone please point me in the right direction.
Thanks for your time,
Reddy